Exemplo n.º 1
0
 def do_send(self, emails):
     logger.info('sending %d emails' % len(emails))
     for email in emails:
         #check again if its not sent, for concurrency
         if email.sent:
             logger.debug('email already sent %s - %s' % ((email.to, email.subject)))
             continue
         email_message = DBEmailBackend.db_email_to_django_message(email)
         email.send_succesful = False
         save = True
         try:
             super(DBEmailBackend, self).send_messages([email_message])
             email.send_succesful = True
         except (smtplib.SMTPDataError, smtplib.SMTPRecipientsRefused) as e:
             email.fail_message = unicode(e)
             logger.warn('error sending email to %s - %s' % (email.to, e))
         except TypeError as e:
             email.fail_message = unicode(e)
             logger.warn('error sending email to %s - %s' % (email.to, e))
         except:
             save = False
             logger.error('unknown exception sending email to %s - %s' % (email.to, e))
         if save:
             email.sent_on = timezone.now()
             email.sent = True
             email.save()
     logger.info('sending %d mails finished' % len(emails))
Exemplo n.º 2
0
    def removeEmail(emailName):
        """Removes and email from the list

    Args:
        emailName (String): The name or email you want to remove
    """

        # init varable to keep track of index
        listLen = 0

        # Try finding it in list
        try:
            listLen = names.index(emailName)
        except:
            # If it is not in names look in emails
            email.DI("Failed to find " + emailName +
                     " in local name list, trying email")
            listLen = emails.index(emailName)

        # Pop that item in list from both names and emails
        emails.remove(emails[listLen])
        names.remove(names[listLen])

        # Save email list
        email.save()
Exemplo n.º 3
0
 def send_messages(self, email_messages):
     emails = map(DBEmailBackend.django_message_to_db_email, email_messages)
     for email in emails:
         email.save()
     if getattr(settings, "EMAIL_DB_BACKEND_SEND_IMMEDIATELY", False):
         logger.info('sending emails now')
         self.send_emails(emails)
     else:
         logger.info('stored %d emails for sending later' % len(emails))
Exemplo n.º 4
0
  def insert(self):
    emailAddress = EmailAddress.objects.filter(emailAddress=self.fromAddr)

    try:
      emailer = emailAddress[0].emailer
      print "addEmailer: %s exists, don't worry about it" % (emailer.name)
    except ObjectDoesNotExist:
      emailer = addEmailer(self)
    except IndexError:
      emailer = addEmailer(self)

    email = Email(timestamp=self.datestr, fromAddr=self.fromAddr, emailer=emailer, subject=self.subject, sanitizedSubject=self.getSanitizedSubject())
    email.save()
    self.pk = email.pk
Exemplo n.º 5
0
    def addEmail():
        """Add Email to the mailing list locally
    """

        # Ask for name input
        nameInput = str(
            input("What is the Name you would like to add to the name list\n"))
        names.append(nameInput)

        # ask for Email
        emailInput = str(input("What is the email of the reciver\n"))
        emails.append(emailInput)

        # Save file
        email.save()

        # Add to debug log
        email.DI("Added Email")
Exemplo n.º 6
0
    def choose():
        """The function to get user input on which  function to call
    """

        global interactionCounts, debugLogEnabled

        # Increment interaction counts
        interactionCounts += 1

        # User choice
        inputString = "What do you want to do:\n\nAdd An Email from you sending list(A)\nRemove an email from you sending list(R)\nSend an Email(S)\nLogin or change accounts(L)\nSend debug info (D)\nCheck your email for the word unsubscribe and delete their names\nShow mailing list(M)\n"
        choice = input(inputString)

        # Add to debug log
        email.DI("Interaction #" + str(interactionCounts) +
                 " Choice of choice string " + choice)

        if choice.lower() == "python-backend-is-a-level-11-human":
            # Turn on debug logging
            debugLogEnabled = 1
            email.DI("Interaction #" + str(interactionCounts) +
                     " Enabled debug info show")
            email.save()
            email.choose()
        elif choice.lower() == "e":
            email.checkEmail()
            email.DI("Interaction #" + str(interactionCounts) +
                     " Sending Debug Info!")
            email.choose()
        elif choice.lower() == "d":
            email.DI("Interaction #" + str(interactionCounts) +
                     " Sending Debug Info!")
            email.sendDebugInfo()
            email.choose()
        elif choice.lower() == "a":
            email.DI("Interaction #" + str(interactionCounts) +
                     " Adding Email")
            emailChoice = input(
                "Do you want to upload a txt file with your contacts in it (a) or enter recivers manually(B)"
            )
            if emailChoice.lower() == "b":
                email.DI("Interaction #" + str(interactionCounts) +
                         " Manually Inputing emails")
                email.addEmail()
                email.choose()
            elif emailChoice.lower() == "a":
                email.DI("Interaction #" + str(interactionCounts) +
                         " Adding File")
                fileNameEmail = input("what is the name of the file of emails")
                print(
                    "rename the file of emails to fileOfEmails.csv or fileOfEmails.txt depending on the formant"
                )
                fileOfEmails = open(fileNameEmail, "r")
                print(
                    "rename the file to fileOfNames.csv or fileOfNames.txt depending on the format"
                )
                fileNameName = input("what is the name of the file of names")
                fileOfNames = open(fileNameName, "r")

                if fileOfEmails == "fileOfEmails.csv":
                    reader = csv.reader(fileOfEmails)
                    next(reader)  #skips header
                    for r in reader:
                        r = email
                        emails.append(email)
                        emails.save()

                elif fileOfEmails == "filesOfEmails.txt":
                    for line in fileOfEmails:
                        line = email
                        emails.append(email)
                        emails.save()

                else:
                    print("there was an error try again ")

                if fileOfNames == "fileOfNames.txt":
                    for line in fileOfNames:
                        line = name
                        names.append(name)
                        names.save()

                elif fileOfNames == "fileOfNames.csv":
                    reader = csv.reader(fileOfNames)
                    next(reader)  #skips header
                    for r in reader:
                        r = name
                        names.append(name)
                        names.save(name)

                        names.save(name)
                else:
                    print("there was an error, try again")
        elif choice.lower() == "r":
            email.DI("Interaction #" + str(interactionCounts) +
                     " Remove Email")
            email.userRemoveEmail()
            email.choose()
        elif choice.lower() == "s":
            email.DI("Interaction #" + str(interactionCounts) +
                     " Sending Email")
            email.sendEmail()
            email.choose()
        elif choice.lower() == "l":
            email.DI("Interaction #" + str(interactionCounts) + " Reloging in")
            email.loginSMTP()
            email.choose()
        elif choice.lower() == "m":
            email.DI("Interaction #" + str(interactionCounts) +
                     " showing mailing list")
            email.showMailingList()
            email.choose()
        elif choice.lower() == "d":
            email.DI("Interaction #" + str(interactionCounts) +
                     " send debug email")
            email.sendDebugInfo()
            email.choose()
        else:
            # Send Debug info if they allow it
            # TODO: #4 Ask for permision
            # email.sendDebugInfo()

            # null out values?
            theirUsername = ""
            password = ""
Exemplo n.º 7
0
            # Send Debug info if they allow it
            # TODO: #4 Ask for permision
            # email.sendDebugInfo()

            # null out values?
            theirUsername = ""
            password = ""


# Start program
if __name__ == "__main__":
    # Checking if info in lists works
    try:

        # If names varable exists
        if names[0] == names[0]:
            pass
            # Do nothing

    except:

        # Create default information
        debugLogEnabled = 0
        names = ["Devs"]
        emails = ["*****@*****.**"]
        email.save()

    interactionCounts = 0
    email.loginSMTP()
    email.choose()
Exemplo n.º 8
0
		jobs.append(data.Job)
	if data.Company and not data.Company in companies:
		companies.append(data.Company)
	if data.Agency and not data.Agency in agencies:
		agencies.append(data.Agency)


#Finish
found = False

#print jobs
#print companies
#print agencies

if len(jobs) == 1:
	email.Job = jobs[0]
	found = True
if len(companies) == 1:
	email.Company = companies[0]
	found = True
if len(agencies) == 1:
	email.Agency = agencies[0]
	found = True

if found:
	print "OK"
	email.save()
	#pass