"Selenium+python UnitTest" sent the mailbox times wrong: Smtplib. Smtpdataerror, Smtplib. Smtpauthenticationerror (ex: 126 e-mail)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.