1. Implement the message sending function
2. Basic use
import smtplib # #导入模块import stringHOST = "smtp.163.com" # #定义远程smtp主机SUBJECT = " test" # #定义发送主题TO = "[email protected]" # #定义接收主机FROM = "[email protected]" # #定义发送主机text = "python" ## # #定义邮件内容BODY = string.join ( # #定义发送格式内容 "from: %s" %FROM, "to : %s" %TO, "subject: %s " %subject, "", text ), "\ r \ n") server = Smtplib. SMTP () # #实例化server. Connect (HOST, " ##") Connect remote host SERVER.STARTTLS () # #启用TLS (Secure transport) mode Server.login ("[email protected]", "ws128711 ") # #校验远程主机server. SendMail (from,[to],body) # #邮件发送功能 [sender, Recipient, Content]server.quit ()
# # 550 error occurs when opening the mailbox client authorization code
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/08/3A/wKiom1neOAWiCToxAAPAa2q7ctc700.png "title=" Screenshot from 2017-10-11 15-43-00.png "alt=" Wkiom1neoawictoxaapaa2q7ctc700.png "/>
Test
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/08/3A/wKiom1neODLAc0gZAASBf5ahbek528.png "title=" Screenshot from 2017-10-11 09-10-28.png "alt=" Wkiom1neodlac0gzaasbf5ahbek528.png "/>
3. Personalized Mail
MIME class : It is an Internet standard that expands the e-mail standard to enable it to support non-ASCII word literals, non-text format attachments (binary, sound, image, etc.), consisting of a multipart (multiple parts) message body, Header information that contains non-ASCII characters.
Example: sending an HTML file
import smtplibfrom email.mime.text import mimetext ## Import Mimetext class import stringhost = "smtp.163.com" subject = " TEST" TO = "[ Email protected] "from = " [email protected] "Msg = mimetext (" "" # #创建MIME对象, make HTML content, type, character encoding, etc. Test
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/08/3A/wKiom1neOiiSNI2kAASqgHv7xeQ770.png "title=" Screenshot from 2017-10-11 09-33-46.png "alt=" Wkiom1neoiisni2kaasqghv7xeq770.png "/>
Python automated operation and maintenance Smtplib