#-*-coding:utf-8-*- ImportSmtplib fromEmail.mime.textImportMimetext fromEmail.headerImportHeader#third-party SMTP servicesmail_host="smtp.qq.com" #setting up the serverMail_user="QQ number @qq.com" #User namemail_pass="password for the application" #PasswordSender='QQ number @qq.com'Receivers= ['Receive Mailbox']#receive mail, can be set as your QQ mailbox or other mailbox #three parameters: the first is the text content, the second plain the text format, the third utf-8 sets the encodingMessage = Mimetext ('Python Mail Send Test ...','Plain','Utf-8') message[' from'] = Header ("Sending Person",'Utf-8')#sent bymessage[' to'] = Header ("Receiving Person",'Utf-8')#Recipientsubject='Use the Python SMTP Mail test for the first time'message['Subject'] = Header (subject,'Utf-8') Try: Smtpobj= Smtplib. Smtp_ssl (Mail_host, 465) Smtpobj.login (mail_user,mail_pass) smtpobj.sendmail (sender, Receivers, message.as_string ())#smtpobj.quit () Print "message sent successfully"exceptSmtplib. Smtpexception:Print "Error: Unable to send message"
Python Send mail