Python Send mail

Source: Internet
Author: User

1 #!/usr/bin/python2 #-*-coding:utf-8-*-3 defSMTP (file):4      fromEmail.mime.textImportMimetext5      fromEmail.mime.multipartImportMimemultipart6     ImportSmtplib7     8     #Msg=mimemultipart ()9     Ten     #Construction Annex 1 One     #att1 = mimetext (open (file, ' RB '). Read (), ' base64 ', ' gb2312 ') A     #att1["content-type"] = ' application/octet-stream ' -     #att1["content-disposition"] = ' attachment; filename= ' +file# here filename can be arbitrarily written, what name to write, what name is displayed in the message -     #Msg.attach (ATT1) the      -     #Construction Annex 2 -     #att2 = mimetext (open (' d:\\123.txt ', ' RB '). Read (), ' base64 ', ' gb2312 ') -     #att2["content-type"] = ' application/octet-stream ' +     #att2["content-disposition"] = ' attachment; filename= "123.txt" -     #Msg.attach (ATT2) +      A     #Add message header atMsg=mimetext (file,_charset='Utf-8')
#to_list =[' [email protected] ', ' [email protected] ', ' [email protected] ' #发送给多个用户 -msg[' to'] ='[email protected]' -msg[' from'] =' Test@163.com' -msg['subject'] ='Backup' - #Send mail - Try: inServer =Smtplib. SMTP () -Server.connect ('smtp.163.com') toServer.login (' Zenghui',' 123456')#xxx for user name, xxxxx for password +Server.sendmail (msg[' from'], msg[' to'],msg.as_string ()) #如果要发送多个用户, replace msg[' to '] with to_list - server.quit () the Print 'sent successfully' * exceptException, E: $ PrintStr (e)Panax Notoginseng if __name__=='__main__': -smtp'Test')

Python Send mail

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.