1 #Send mail using the Smtplib module2 ImportSmtplib3 fromEmail.mime.textImportMimetext4 fromEmail.headerImportHeader5 6 #Send Mailbox7Sender ='[email protected]'8 #Receive Mailbox9Receiver ='[email protected]'Ten #Send Message subject OneSubject ='Test Message Subject' A #Send Mailbox Server -SmtpServer ='smtp.163.com' - #Send email user/password theUsername ='[email protected]' -Password ='XXX' - #Assemble message content and title, Chinese required parameter ' utf-8 ', single byte character not required -msg = Mimetext ('Hello! This is a test mail! ','Plain','Utf-8') +msg['Subject'] = Header (subject,'Utf-8') -msg[' from'] ='Larry<[email protected]>' +msg[' to'] ="[email protected]" A #sign in and send mail atSMTP =Smtplib. SMTP () - Smtp.connect (smtpserver) - smtp.login (username, password) - Smtp.sendmail (sender, receiver, msg.as_string ()) -Smtp.quit ()
Python uses the Smtplib module to send mail