ImportSmtplib fromEmail.mime.textImportMimetext fromEmail.headerImportHeader#third-party SMTP servicesmail_host="smtp.qq.com" #setting up the serverMail_user="xxxxxx" #User namemail_pass="Plcfthkdtpoxcabh" #password QQ requires authorization codeSender='[email protected]'Receivers= ['[email protected]']#receive mail, can be set as your QQ mailbox or other mailboxmessage= Mimetext ('Python Mail send content test ...','Plain','Utf-8') message[' from'] = Header ("This writes the name of the sender.",'Utf-8') message[' to'] = Header ("This is the recipient name",'Utf-8') Subject='Python SMTP Mail test-Topics'message['Subject'] = Header (subject,'Utf-8')Try: Smtpobj=Smtplib. Smtp_ssl () smtpobj.connect (Mail_host,465)#465 is the SMTP port numberSmtpobj.login (Mail_user,mail_pass)Print(Help (Smtpobj.sendmail)) Smtpobj.sendmail (sender, Receivers, message.as_string ())Print("message sent successfully")exceptSmtplib. Smtpexception:Print("Error: Unable to send message")
Python e-mail