Function: Smtplib module is to send e-mail through mail server, is the implementation of SMTP client, Support message format: text, HTML, Image, Excel and so on.
1 #!/usr/bin/env python
2 #Coding:utf-83 ImportSmtplib4 Importstring5Host ="smtp.qq.com" #defining an SMTP host6Subject ="Test email from Python" #Defining message Topics7To_mail ="[email protected]" #Mail Recipient8From_email ="[email protected]" #message Sender9Password ="Pass" #message sender Mailbox PasswordTenText ="Hello python!" #Message Content OneBODY = String.Join ((#assemble the message subject content of the SendMail method, and the sections are split with "\ r \ n" A "From :%s"%From_email, - "To :%s"%To_mail, - "Subject:%s"%subject, the "", - text -),"\ r \ n") -Server = Smtplib. SMTP ()#Create an SMTP () object +Server.connect (Host," -")#connect to an SMTP host by using the Connect method -Server.starttls ()#Start Secure transfer Mode +Server.login (From_email,password)#Email Account login Authentication AServer.sendmail (From_email,to_mail,body)#Send mail atServer.quit ()#Disconnecting SMTP Connections
Send e-mail module smtplib