PYTHON-SMTP sending messages (HTML, pictures, attachments)

Source: Internet
Author: User

Objective:

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.

One, Python send HTML mail
#-*-Coding:utf-8-*-# @Time: 2018/6/6 morning 11:27# @Author: wang# @File: Test_mail_html.pyimport smtplibfrom Emai    L.header Import headerfrom email.mime.multipart import mimemultipartfrom email.mime.text import Mimetextdef sendMail (): # to define the relevant data, please replace your real data SmtpServer = ' smtp.163.com ' sender = ' [email protected] ' #receiver可设置多个, using "," separating rec Eiver = ' [email protected],[email protected],[email protected] ' username = ' [email protected] ' p Assword = ' 2018 ' msg = Mimemultipart () Boby = "" "
Ii. python send mail with attachments
#添加report附件att = MIMEText(open("/report/html.zip", "rb").read(), "base64", "utf-8")att["Content-Type"] = "application/octet-stream"times = time.strftime("%m_%d_%H_%M", time.localtime(time.time()))filename_report = ‘FM_Android_Report‘+‘_‘+times+‘.zip‘att["Content-Disposition"] = ‘attachment; filename= %s ‘ %filename_reportmsg.attach(att)
Third, Python send the message body with pictures
msg = MIMEMultipart()boby = """    

Above ~ ~ for you to help, praise it ~??

PYTHON-SMTP sending messages (HTML, pictures, attachments)

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.