How to send email from Python and Django using Office 365

how to send email via office 365 in python django

To send email using python script via Office 365, use below code. This code is tried and tested.

Email contains two body part, html and text. You can use Django template in email.

It is always advisable to store credentials in separate config file and not to commit that file on Github.

Same code can be used to send email via Gmail and Google Apps with slight modification. Use below settings:

Gmail :

Google Apps:


Warning: Do not send too many mail using python script via Gmail. Your account may be blocked. Daily email limit is 500 or 1000 emails. 

If you are sending more than 500 emails daily, I recommend using Mailgun. They provide nice api and you can send 20000 emails per month for free.

Read also : How to send bulk emails using Mailgun and Python-Django.

Please comment in case of any query.

(Visited 1,893 times, 1 visits today)

You must read this :

2 thoughts on “How to send email from Python and Django using Office 365”

Leave a Reply

Your email address will not be published. Required fields are marked *