Python 通过 qq 邮箱发送邮件

获取授权码

设置 -> 帐户 -> POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务 -> IMAP/SMTP服务 -> 开启 -> 发短信“配置邮件客户端”到1069070069

测试

发送邮件
ECMBP:~ e.c.$ ipython 
Python 3.7.4 (default, Sep  7 2019, 18:27:02) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:                                                                          

In [1]: import smtplib                                                           

In [2]: smtp = smtplib.SMTP_SSL('smtp.qq.com', 465)                              

In [3]: smtp.ehlo()                                                              
Out[3]: 
(250,
 b'smtp.qq.com\nPIPELINING\nSIZE 73400320\nAUTH LOGIN PLAIN\nAUTH=LOGIN\nMAILCOMPRESS\n8BITMIME')

In [4]:                                                                          

In [4]: smtp.login('d0o0bz@qq.com', '授权码')                          
Out[4]: (235, b'Authentication successful')

In [5]:  

In [5]: smtp.sendmail('d0o0bz@qq.com', 'e.c.admin@d0o0bz.cn', 'Subject: this is 
    ...: a test mail\nthis is content. ')                                        
Out[5]: {}

In [6]: smtp.quit()                                                             
Out[6]: (221, b'Bye')
ECMBP:~ e.c.$ pip3 install yagmail
Collecting yagmail
  Downloading https://files.pythonhosted.org/packages/f6/5b/1e7ec5a612c831154cb1dd01f4211f4e4501083084e3d9e5ed9789698624/yagmail-0.11.220-py2.py3-none-any.whl
Installing collected packages: yagmail
Successfully installed yagmail-0.11.220
ECMBP:~ e.c.$   
ECMBP:~ e.c.$ ipython 
Python 3.7.4 (default, Sep  7 2019, 18:27:02) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:  
                                                          
In [1]: import yagmail                                                          

In [1]: with yagmail.SMTP(user='d0o0bz@qq.com', password='授权码', hos
    ...: t='smtp.qq.com', port='465') as yag: 
    ...:     yag.send('e.c.admin@d0o0bz.cn', 'This is a Title', 'a Content') 
    ...:                                                                         

In [2]:   
接收邮件
接收邮件