# ! / Usr / bin / Python the env # - * - Coding: UTF-. 8 - * - # @time: 2019-05-29 11:28 # @author: zhouyang # @file: send_mailAtt.py '' ' transmission belt there mail attachments '' ' Import smtplib from email.mime.text Import MimeText from email.mime.multipart Import MimeMultipart the smtpserver = ' smtp.126.com ' sENDER = ' [email protected] ' # sender password = ' * A ****** ' # authorization code # Receive='*****[email protected] '# receiving side the receive = [ ' *****[email protected] ' , ' *****[email protected] ' ] # simultaneously transmitting to people Subject = ' message header ' Content = ' <HTML> <h1 of style = "Color: Red"> this is the message body </ h1 of> </ HTML> ' # configured Annex the send_file = Open (R & lt ' C: \ the Users \ Administrator \ PycharmProjects \ untitled6 \ 2019-05-28-16_52_10test.html ' , ' RB ' ) .read () ATT = MimeText (the send_file, ' Base64 ','utf-8') att['Content-Type']='application/octet-stream' att['Content-Disposition']='attachment;filename="2019-05-28-16_52_10test.html"' #发送带附件的邮件 msgRoot=MIMEMultipart() msgRoot.attach(MIMEText(content,'html','utf-8')) msgRoot['Subject']=subject msgRoot['From']=sender #msgRoot [ 'the To'] = the receive msgRoot [ ' the To ' ] = ' , ' .join (the receive) msgRoot.attach (ATT) # E-mail SMTP = smtplib.SMTP_SSL (the smtpserver, 465 ) # server identifies the user identity smtp. the HELO (smtpserver) # server returns the results confirm smtp.ehlo (smtpserver) # Log mail server user name and authorization code smtp.login (SENDER, password) # sending mail smtp.sendmail (SENDER, receive, msgRoot.as_string ()) the SMTP. quit () Print ( ' transmission success ' )