Add: Send mail
Outbox: [Email protected] alex3714 custom client login account and password are: [email protected] sbalex3714
Inbox: [Email protected] alex371
Python failed to send mail via SMTP:
Error 1:SMTPLIB. Smtpauthenticationerror: (550, B ' User has no permission ')
When we use Python to send a message, the custom client logs in based on the user name and password, and then uses the SMTP service to send mail, and the newly registered 163 mailbox is not turned on by default (enabled by default for the specified mailbox master client), so the login is always denied. Workaround (Take 163 mailboxes for example): Enter 163 mailbox-Setup-Client authorization password-on (authorization code is a private password used to log in to a third-party mail client)
Error 2:SMTPLIB. Smtpauthenticationerror: (535, B ' error:authentication failed ')
Take 163 mailbox As an example, the authorization code will be set when the POP3/SMTP service is turned on and the client authorization password is turned on, instead of Smtplib. Password in the SMTP (). Login (User,password) method.
#!/usr/bin/python#-*-coding:utf-8-*-ImportSmtplibImportEmail.mime.multipartImportemail.mime.textmsg=Email.mime.multipart.MIMEMultipart () msg['Subject'] ='you are the wind, I am the sand, wrapped around my home'msg[' from'] ='[email protected]'msg[' to'] ='[email protected]'content=" "Come on , swing together ." "txt= Email.mime.text.MIMEText (content,_charset='Utf-8') Msg.attach (TXT) SMTP=Smtplib. SMTP () Smtp.connect ('smtp.163.com',' -') Smtp.login ('Python4_mail','sbalex3714') Smtp.sendmail ('[email protected]','[email protected]', Msg.as_string ()) Smtp.quit ()Print('Mail sent successfully email has send out!')
python Mail Sending tool (Smtplib)
#!/usr/bin/python#-*-coding:utf-8-*-ImportSYSImportSmtplibImportEmail.mime.multipartImportEmail.mime.textserver='smtp.163.com'Port=' -'defSendMail (server,port,user,pwd,msg): SMTP=Smtplib. SMTP () smtp.connect (server,port) smtp.login (user, PWD) smtp.sendmail (msg[' from'], msg[' to'], msg.as_string ()) Smtp.quit ()Print('Mail sent successfully email has send out!')if __name__=='__main__': Msg=Email.mime.multipart.MIMEMultipart () msg['Subject'] ='you are the wind, I am the sand, wrapped around my home'msg[' from'] ='[email protected]'msg[' to'] ='[email protected]'User='Python4_mail'pwd='sbalex3714'content=sys.argv[-1] txt= Email.mime.text.MIMEText (Content, _charset='Utf-8') Msg.attach (TXT) sendmail (server,port,user,pwd,msg) # How to: Python The file name of the above content. py Hello, Egon hahaha.
Shell Third: basic syntax