marrow mailer python keyerror encryption

287 views Asked by At
import requests
from marrow.mailer import Mailer, Message

from app import celery
from app.helpers.versioning import strip_tags


@celery.task(name='send.email.post.smtp')
def send_mail_via_smtp_task(config, payload):
    print config,payload
    mailer_config = {
        'transport': {
            'use': 'smtp',
            'host': config['host'],
            'username': '[email protected]',
            'password': '99121Padma',
            'tls': config['encryption'],
            'port': config['port']
        }
    }

    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']
    mailer.send(message)
    mailer.stop()

the above code is giving me an error ERROR/MainProcess] Task send.email.post.smtp[a58e3232-ffe2-42d0-ad53-03dc4dc6b980] raised unexpected: KeyError('encryption',) what's causing the problem here?

1

There are 1 answers

0
metmirr On

The error says config dictionary does not have a key named encryption, so when you trying to get the value of this key raising the KeyError. Make sure config dictionary have it.

mailer_config = {
        ...
        'tls': config['encryption'],
}