Python3 smtp Send mail

Source: Internet
Author: User

The SMTP (Simple Mail Transfer Protocol) is simply the message Transfer Protocol, which is a set of rules for sending mail from the source address to the destination, and it controls the way the letters are relayed.

Python's Smtplib provides a convenient way to send e-mails. It provides a simple encapsulation of the SMTP protocol.

First, the opening of the SMTP service, take authorization code

Not much nonsense said, we directly according to the following Operation first opened the QQ mailbox in the SMTP service, take our authorization code, or can not send the mailbox.

Second, start the code to send e-mail

Here we need to use Python's two packages to send mail: smtplib and email

Python's Email module contains a number of useful message formatting functions that can be used to create mail "parcels".

Using the Mimetext object, an empty message was created for the underlying MIME (Multipurpose Internet mailextensions, Multipurpose Internet Mail Extension Type) protocol transfer, and finally sent out through the high-level SMTP protocol.

Mimetext object MSG includes sending and receiving email addresses, message bodies, and topics that Python can use to create a properly formatted message.

The Smtplib module is used to set information about the server connection. The code is as follows:

After configuration, we run the. py file.

We open our QQ mailbox, we will see the email we just sent.

The above is a simple code to send the message, we can use to wrap it up as a function, we need to send a call on the line, we can add additional features.

Finally attach the code cloud address, you can download to write: Https://gitee.com/zengjielin/smtp_sends_mail

Python3 smtp 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.