The original code is as follows:
ImportSmtplib fromEmail.mime.textImportMimetext fromEmail.headerImportHeader#the server to sendSmtpServer ='smtp.126.com'#Email user name/password to senduser ='[email protected]'Password='XXX'#sent MailboxSender ='[email protected]'#Mailboxes receivedReceiver ='[email protected]'#Send Mailbox TopicSubject ='Test_mail'#writing an HTML-type message bodymsg = Mimetext ('good ','HTML','Utf-8') msg['Subject'] = Header (subject,'Utf-8')#connect to send mailSMTP =Smtplib. SMTP () smtp.connect (smtpserver) smtp.login (User,password) Smtp.sendmail (sender,receiver,msg.as_string ()) Smtp.quit ()
First, the phenomenon:
When sending a message, run the Times wrong Smtplib. Smtpdataerror, such as:
Ii. Solutions
① by online inquiry: Because 126 mailbox does not open "Authorization code ", as shown should be turned on:
② but run the code again or error:smtplib. Smtpauthenticationerror, such as, prompt login failure:
The reason: the password in the code should be changed to an authorization password.
③ continues to run, but the code is still an error:smtplib. Smtpdataerror: (554, B ' dt:spm 126 SMTP4
The reason for the error is not adding the following code:
# the reason for the error is that "sender and recipient parameters are not defined msg['from'[email protected] ' msg['to'[email protected]'
Plus, finally solve the problem of sending mail failed.
The complete code is as follows: (due to confidentiality, self-replacement)
ImportSmtplib fromEmail.mime.textImportMimetext fromEmail.headerImportHeader#the server to sendSmtpServer ='smtp.126.com'#Email user name/password to senduser ='[email protected]'Password='XXX'#sent MailboxSender ='[email protected]'#Mailboxes receivedReceiver ='[email protected]'#Send Mailbox TopicSubject ='Test_mail'#writing an HTML-type message bodymsg = Mimetext ('good ','HTML','Utf-8') msg['Subject'] = Header (subject,'Utf-8') msg[' from'] ='[email protected]'msg[' to'] ='[email protected]'#connect to send mailSMTP =Smtplib. SMTP () smtp.connect (smtpserver) smtp.login (User,password) Smtp.sendmail (sender,receiver,msg.as_string ()) Smtp.quit ()
"Selenium+python UnitTest" sent the mailbox times wrong: Smtplib. Smtpdataerror, Smtplib. Smtpauthenticationerror (ex: 126 e-mail)