One, 163 mailbox settings
Go to 163 email, click on the Pop3/smtp/imap in the settings
Open the SMTP service, if not turned on, click on the settings, mobile phone number verification after checking the open can, open the following image:
The main use is the SMTP server: smtp.163.com
Then set the client authorization password:
Remember the password if you do not remember the password in this re-authorization. Mobile phone number verification can be re-authorized. This password will be used when writing code.
After Setup is successful, start writing code
Second, the Code implementation
1 #--*--coding:utf-8--*--2 3 #Import the required libraries4 ImportSmtplib#This library is used to send mail5 fromEmail.mime.textImportMimetext#used to write email subject, content, etc.6 7 8 #First step: Set up login mailbox Data9 #SMTP ServerTenSmtp_server ='smtp.163.com' #what appears after you have just set up 163 mailboxes One #set e-mail address, your own mailbox, sender ASender ='[email protected]' - #email password, 163 client authorization password in mailbox settings -PWD =' xxxxxxx' the - - #Step Two: Set what to send - #Send content Text +Text ='python automatically sends messages' - #Convert the sent content to the text content of the message +TXT =mimetext (text) A #Set Message subject attxt['Subject'] ='Test Send email' - #set up a mail sender -txt[' from'] =Sender - - - #Step three: Send mail in #Create an SMTP server -Mail_server = Smtplib. SMTP (smtp_server,25) to #Login Server + Mail_server.login (SENDER,PWD) - #Send mail theMail_server.sendmail (sender,['[email protected]'],txt.as_string ()) * #The first parameter is the sender, the second parameter is the receiver, you can add more than one example: [' [email protected] ', ' [email protected] ', ' $ #The third parameter is what is sentPanax Notoginseng - the #Fourth step: Exit Login +Mail_server.quit ()
Third, view the results
View the results in your inbox:
To view the contents of a message:
Python for sending mail