How to send SMTP email for office365 with python using tls/ssl

后端 未结 4 1221
时光取名叫无心
时光取名叫无心 2021-02-01 06:25

I am trying to send an email from my office365 corporate account using python. I am new to python. This code previously worked when using my hotmail account, however now that I

4条回答
  •  野的像风
    2021-02-01 07:29

    Well, you are almost there. The following code will do the trick:

    import smtplib
    
    mailserver = smtplib.SMTP('smtp.office365.com',587)
    mailserver.ehlo()
    mailserver.starttls()
    mailserver.login('user@company.co', 'password')
    mailserver.sendmail('user@company.co','user@company.co','python email')
    mailserver.quit()
    

    Use the following links for more information:

    http://www.aventistech.com/2016/03/07/python-send-email-via-office-365-tls/

    https://docs.python.org/3/library/smtplib.html

    https://gist.github.com/jasonjoh/3ec367594c3fa662ee983a617bdc7deb

提交回复
热议问题