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