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 picturesmsg = MIMEMultipart()boby = """
Above ~ ~ for you to help, praise it ~??
PYTHON-SMTP sending messages (HTML, pictures, attachments)