In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to analyze the email function of Python. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
Before to do a mysql slow query timing sending program, studied the module of python sending email. Python can send mail to smtplib libraries and email libraries.
The use of stmplib
The initialization syntax is as follows:
# Connect to the SMTP server
S = smtplib.SMTP ('smtp.XXXX.com')
# send an email. Msg is a string that represents the content of the message.
S.sendmail (from_addr, to_addrs, msg)
# disconnect
S.quit ()
Second, the use of email
Some knowledge about MIME
Multipurpose Internet Mail extension (MIME,Multipurpose Internet Mail Extensions) is an Internet standard that extends the e-mail standard to support mail messages in a variety of formats, such as non-ASCII characters, binary format attachments, and so on.
In the email format defined by RFC2822, the email body is only a simple ASCII-encoded character sequence. MIME extends the email format to support non-ASCII-encoded text, non-text attachments and mail bodies containing multiple parts (multi-part).
The MIME message consists of the message header and the message body, that is, the mail header and the mail body. The middle is separated by blank lines.
1. Message header: includes information such as sender (from), recipient (to), email subject (subject), date of receipt (date), MIME version, email content type, etc. Each message is called a domain and consists of a domain name followed by a ":" and the content of the message, and the first line of the domain must be written at the top.
2. Mail body: there are text/plain (plain text) and text/html (hypertext), which are indicated by the "content type" field of the header. It can exist at the same time, or there can be only one. This is why some emails can be viewed in both html and text format. The mail body is divided into multiple segments, called Payload. Each segment also includes the beginning and end of the segment, separated by blank lines in the middle.
There are 3 types of multipart:
Multipart/mixed
Multipart/related
Multipart/alternative .
To add an attachment to an email, you need to define a multipart/mixed segment:
If plain text hypertext coexists, define multipart/alternative
If there are embedded resources, define multipart/related.
3. Attachment (attach). When you send an e-mail, you can send files from this computer together. There can be 0 or more attachments, as long as the total size of the attachment does not exceed the maximum capacity declared by the mail server.
Class email.mime.text.MIMEText (_ text [, _ subtype [, _ charset]])
The body text used to generate the MIME object: _ text specifies the message content, _ subtype specifies the message type, and _ charset specifies the encoding.
Class email.mime.multipart.MIMEMultipart ()
Used to generate a MIME object for a mail body that contains multiple parts
Three simple examples are introduced:
An example of sending to multiple people:
#! / usr/bin/evn python
Import time
Import smtplib
From email.mime.text import MIMEText
Mail_body='hello, this is the mail content from python and it is sended to two emails!'
Fromer='qilong.yangql@gmail.com'
# # Note that the sender must be an array, otherwise the received email shows that the recipient is a string truncated by ";"
Sender= ['5XXX2roomqq.compositional journal journal yangXXXroom163.com']
Msg=MIMEText (mail_body)
Msg ['Subject'] =' hello world'
Msg ['From'] = fromer
Msg ['To'] ='; '.join (sender)
Msg ['date'] = time.strftime (' a,% d% b% Y% H:%M:%S% z')
S=smtplib.SMTP ('smtp.XXXXX.com')
S.sendmail (fromer,sender,msg.as_string ())
S.quit ()
After reading the above, do you have any further understanding of how to analyze the email sending function of Python? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.