selenium - SMTP to send mail - environment configuration

1. E-mail server:

  • qq mailbox using smtp.qq.com
  • 163 mailbox using smtp.163.com

 

2. 运行时报错:smtplib.SMTPAuthenticationError: (535, b'Login Fail. Please enter your authorization code to login.

 

 3. You need to configure the mailbox to QQ-mail as an example:

Settings -> Accounts -> turn on the SMTP service

Send an SMS to a specified number, the received authorization code

  

 

 4. The setting is completed, you can write a simple message transmission code as follows:

. 1  Import smtplib
 2  from email.mime.text Import MimeText     # the MIME (the Multipurpose the Internet Mail Extensions) type of Multipurpose Internet Mail Extensions 
. 3  from email.header Import Header
 . 4  
. 5  
. 6  # Transmit mailbox server 
. 7 the smtpserver = ' smtp.qq.com '     # QQ-mail 
. 8  # the smtpserver = 'smtp.163.com' mailbox # 163 
. 9  # the smtpserver = 'smtp.mxhichina.com' mailbox # staple 
10  
. 11  # transmit mailbox user / password 
12 is user = ' 123456789' 
13 is password = ' fjdkljsf ' 
14  
15  # send mail / mail receiving 
16 SENDER = ' [email protected] ' 
. 17 Receiver = ' [email protected] ' 
18 is  
. 19  # E-mail topic 
20 is Subject = ' test3333 ' 
21 is  
22 is  # HTML type message body 
23 is MSG = MimeText ( ' <HTML> <h1 of> Hello ~~~~~~ </ h1 of> </ HTML> ' , ' HTML ' , ' UTF-. 8 ')
24 msg['Subject'] = Header(subject, 'utf-8')
25 
26 # 连接并发送邮件
27 smtp = smtplib.SMTP()
28 smtp.connect(smtpserver)
29 smtp.login(user, password)
30 smtp.sendmail(sender, receiver, msg.as_string())
31 smtp.quit()

 

5. OK, the message received friends ~

 

Guess you like

Origin www.cnblogs.com/xiaochongc/p/12606986.html