Python implementation send e-mail

It is achieved by sending email Python smtplib.SMTP class method.

SMTP target lists common methods:

sendmail (from, to, msg [, mopts, ropts]): the msg from to from to send (or represented as a list of tuples) selectively disposed ESMTP message (mopts) and recipient (ropts) option

login (user, passwd): using a user name and password SMTP server

 

These are the methods that will be used next. SMTP authorization code first need to obtain the following example of the required QQ mailbox.

QQ mailbox page, click Settings, Account, down to the SMTP service to open the service, and generate an authorization code.

 

from smtplib Import the SMTP
 from email.header Import Header
 from email.mime.text Import MimeText 


DEF main ():
     # Please amend its own following the message sender and receiver 
    SENDER = ' [email protected] '   # E-mail address of the sender 
    = receivers [ ' [email protected] ' ]   # e-mail address of the recipient 
    Message = MimeText ( ' HelloPython ' , _subtype = ' Plain ' , _CHARSET = ' UTF-. 8 ' )
    Message [ ' the From ' ] = Header ( ' Your Old Friend ' , ' UTF-. 8 ' )   # mail sender 
    Message [ ' the To ' ] = Header ( ' Darling Jay ' , ' UTF-. 8 ' )    # mail receiving by 
    message [ ' the Subject ' ] = header ( ' the to Jay Darling ' , ' UTF-. 8 ' ) # mail header 
    smtper = the SMTP ( ' smtp.qq.with ')
    # Modify their own login password below 

    smtper.login (SENDER, ' bfxnuspuivpebbij ' )   # QQ mailbox smtp authorization code 
    smtper.sendmail (SENDER, Receivers, message.as_string ())
     Print ( ' e-mail transmission is complete! ' ) 


IF  __name__ == ' __main__ ' : 
    main ()

 

 After sending successfully, into the test mailbox QQ number, the message was received successfully found

 

 So a simple to use Python mail transmission function is realized.

 

Guess you like

Origin www.cnblogs.com/lesliechan/p/11566814.html