16.2 发送电子邮件

16.2 发送电子邮件,第1张

16.2 发送电子邮件

你可能对发送电子邮件很熟悉,通过 Outlook、Thunderbird 或某个网站,如 Gmail或雅虎邮箱。遗憾的是,Python 
没有像这些服务一样提供一个漂亮的图形用户界面。作为替代,你调用函数来执行 SMTP 的每个重要步骤,就像下面的交互式环境的例子

注意       不要在 IDLE 中输入这个例子,因为smtp.example.com、[email protected]、MY_ SECRET_PASSWORD  和 
[email protected]  只是占位符。这段代码仅仅勾勒出 Python 发送电子邮件的过程。

>>>  import  smtplib
>>>  smtpObj  =  smtplib.SMTP('smtp.example.com',  587)
>>>  smtpObj.ehlo()
(250,  b'mx.example.com  at  your  service,  [216.172.148.131]nSIZE  35882577 
n8BITMIMEnSTARTTLSnENHANCEDSTATUSCODESnCHUNKING')
>>>  smtpObj.starttls()
(220,  b'2.0.0  Ready  to  start  TLS')
>>>  smtpObj.login('[email protected]',  'MY_SECRET_PASSWORD')
(235,  b'2.7.0  Accepted')
>>>  smtpObj.sendmail('[email protected]',  '[email protected]',  'Subject:  So long.nDear  Alice,  
so  long  and  thanks  for  all  the  fish.  Sincerely,  Bob')
{}
>>>  smtpObj.quit()
(221,  b'2.0.0  closing  connection  ko10sm23097611pbd.52  -  gsmtp')
在下面的小节中,我们将探讨每一步,用你的信息替换占位符,连接并登录到
SMTP 服务器,发送电子邮件,并从服务器断开连接。
 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5689393.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存