Question

I'm using smtplib sending out mails, rather frequently. I'm using my own SMTP server as a relay. The problem is every time a connection is issued smtplib.SMTP(...) the whole process is blocked. I'm new to python(v3), and is wondering if smtplib already support asynchronous mailing. I also tried to delegate the blocking work load to a MTA such as sendmail and then issue separate processes in python code so that it doesn't block the flow. I'm not sure if it's good practice. What would be a good solution for my case?

Was it helpful?

Solution

You can do that with a message queue (like rabbit MQ for example). Instead of sending an email directly, you leave the message to the queue. Posting into the queue returns immediately. Then, in the background, some process is emptying the queue and sending emails.

More info here: http://www.rabbitmq.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top