#! / usr / bin / python3 Import smtplib from email.mime.text Import MimeText from email.header Import Header # third-party SMTP service mail_host = " smtp.mxhichina.com " # Set the server mail_user = " xxx @ tian-wang. COM " # username mail_pass = " **** " # password SENDER = ' [email protected] ' Receivers = [ ' [email protected] ' ] # incoming mail, can be set to your mailbox or other QQ-mail message MimeText = ( 'Python sending test messages ... ' , ' Plain ' , ' UTF-. 8 ' ) Message [ ' the From ' ] = Header ( " novice Tutorial " , ' UTF-. 8 ' ) Message [ ' the To ' ] = Header ( " Test " , ' UTF-. 8 ' ) Subject = ' the Python test the SMTP Mail ' message [ ' the Subject ' ] = Header (Subject, 'utf-8') the try : smtpObj = smtplib.SMTP () smtpObj.connect (mail_host, 25 ) # 25 is the SMTP port number smtpObj.login (mail_user, mail_pass) smtpObj.sendmail (mail_user, Receivers, message.as_string ()) Print ( " e-mail sent success " ) the except smtplib.SMTPException AS E: Print (E) Print ( " Error: Can not send Mail " )
Reference #:
#https: //www.runoob.com/python3/python3-smtp.html
#https: //www.runoob.com/python/python-email.html
Ali cloud smtp service configuration
https: // help. aliyun.com/knowledge_detail/36687.html?spm=5176.2000002.0.0.37167d0acjcNSF
https://help.aliyun.com/wordpower/623806-1.html