Exemple #1
0
def sendMail(mail):

    try:
        message = Message(author="*****@*****.**", to=mail)

        # mail subject, obviously
        message.subject = "Subject"

        # plain text variant:
        message.plain = "Please view this mail with html enabled."

        # when pressing "reply", send mail to:
        message.reply = "*****@*****.**"

        # HTML variant:
        message.rich = """ 
        
        <h1>Header</h1>
        <p>some text</p>

        """

        message.attach(name='path-to-attachment.pdf')

        mailer.send(message)
        print('successfull sent mail to ' + mail)
        return True

    except:
        print('There was an error for mail ' + mail + ", skipping this.")
        return False
Exemple #2
0
def send_email_task_smtp(payload):
    smtp_config = get_smtp_config()
    mailer_config = {'transport': {'use': 'smtp', **smtp_config}}

    mailer = Mailer(mailer_config)
    mailer.start()
    message = Message(author=payload['from'], to=payload['to'])
    message.subject = payload['subject']
    message.plain = strip_tags(payload['html'])
    message.rich = payload['html']
    if payload['bcc'] is not None:
        message.bcc = payload['bcc']
    if payload['reply_to'] is not None:
        message.reply = payload['reply_to']
    if payload['attachments'] is not None:
        for attachment in payload['attachments']:
            message.attach(name=attachment)
    try:
        mailer.send(message)
        logging.info('Message sent via SMTP')
    except urllib.error.HTTPError as e:
        if e.code == 554:
            empty_attachments_send(mailer, message)
    mailer.stop()