Python Simple Mail Send source code

Source: Internet
Author: User

Environment:

Python27

Main code:

#-*-coding:utf-8-*-" "Created on October 18, 2016 @author:xuxianglin" "ImportSmtplib;  fromEmail. MimetextImportMimetext fromEmail.utilsImportformataddrfrom_addr='[email protected]' #Sender e-mail account, for easy maintenance in the back, so write a variableTo_addr='[email protected]' #recipient mailbox account, for easy maintenance back, so write a variabledefMail (): RET=TrueTry: Msg=mimetext ('Cloud Server Error','Plain','Utf-8') msg[' from']=FORMATADDR (["Link", From_addr])#corresponding sender's mailbox nickname in parentheses, sender's email accountmsg[' to']=FORMATADDR (["Link", To_addr])#corresponding recipient mailbox nickname in parentheses, Recipient's email accountmsg['Subject']="Ali Server Error" #the subject of the message, it can also be said to be a titleServer=smtplib. SMTP ("smtp.163.com", 25)#SMTP server in the sender's mailbox, port isServer.set_debuglevel (1) Server.login (from_addr,"xxxxxx")#the corresponding in parentheses is the sender's email account, email passwordServer.sendmail (from_addr,[to_addr,],msg.as_string ())#the corresponding in parentheses is the sender's mailbox account, the recipient's email account, the emailServer.quit ()#This is the meaning of closing the connection.    exceptException:#if the statement in the try is not executed, the following ret=false is executedret=FalsereturnRetret=Mail ()ifret:Print("OK")#If the send is successful, it will return OK, wait 20 seconds or so to receive the messageElse:    Print("failed")#returns failed if the send fails

Python Simple Mail send source code

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.