Python implementation Send mail

Source: Internet
Author: User

The following program takes advantage of the SMTP protocol to send a solid message. The next optimizations make it possible to collect messages using POP3 or IMAP protocols.

#/usr/bin/env python#-*-Coding:utf8-*-ImportSmtplib fromEmail.mime.textImportMimetextclassMail_helper:def __init__(self): Self.username= Raw_input ('Username:') Self.password= Raw_input ('Password:')    defSend (self): host='smtp.163.com'Port= 25receiver= Raw_input ('Send to:') Title= Raw_input ('Title:') Body='<p>'+raw_input ('content:')+'</p>'msg= Mimetext (Body,'HTML') msg['subject'] =title msg[' from'] =self.username msg[' to'] =receiver S=Smtplib.        SMTP (host, Port) S.login (Self.username, Self.password) s.sendmail (self.username, receiver, msg.as_string ()) Print 'Mail has been sent.'if __name__=='__main__': Mailer=Mail_helper () mailer.send ( )

Python implementation 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.