Python3 uses smtplib to send emails

Source: Internet
Author: User
Tags aliyun

The smtplib module is the implementation of the smtp Simple Mail transmission protocol client. For the sake of universality, sometimes attachments or images are required to be sent and the content is loaded using email. mime. The Code is as follows:

Import smtplibimport email. mime. multipartimport email. mime. textmsg = email. mime. multipart. MIMEMultipart () msg ['from'] = 'ustchacker @ tom.com 'msg ['to'] = 'blablabla @ aliyun.com' msg ['subobject'] = 'test' content = ''' hello, this is an automatic email. Www.ustchacker.com ''' txt = email. mime. text. MIMEText (content) msg. attach (txt) smtp = smtplibsmtp = smtplib. SMTP () smtp. connect ('smtp .tom.com ', '25') smtp. login ('ustchacker @ tom.com ', 'Password') smtp. sendmail ('maid @ tom.com ', 'blablabla @ aliyun.com', str (msg) smtp. quit ()

View email content:


As you can see, to send emails in Python, you only need to use the connect (connect to the mail server), login (login verification), and sendmail (send mail) steps, which is simple and convenient.


Reprinted Please note:

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.