#!は/ usr / binに/ PythonのENV #- * -コーディング:UTF-8 - * - 。 #@time:2019年5月29日11:28 #の@author:zhouyang #1 @file:send_mailAtt.py '' ' 伝動ベルトそこにメールの添付ファイル '' ' インポートしたりするsmtplib から email.mime.text インポートします:MIMEText から email.mime.multipart インポートのMimeMultipart SmtpServerは = ' smtp.126.com ' 送信者 = ' [email protected] ' #の送信者の パスワード= ' * ****** " #の認証コード #Receive='*****[email protected] 'は#受信側 受信= [ ' *****[email protected] ' ' *****[email protected] ' ] #同時に送信します人への 件名 = ' メッセージヘッダ' コンテンツ = ' <HTML> <スタイル=のH1 "カラー:レッド">これは、メッセージ本文</ HTML> <の/ H1>である' #構成された附属書は、 send_file =オープン(R&LT " C:\ユーザー\管理者\ PycharmProjects \ untitled6 \ 2019-05-28-16_52_10test.html ' ' RB ' ).read() ATT =ます:MIMEText(send_file、' Base64で"、「UTF-8' ) ATT [ ' のContent-Type ' ] = ' アプリケーション/オクテットストリーム' ATT [ ' コンテンツの廃棄' ] = ' アタッチメント;ファイル名= "2019-05-28-16_52_10test.html" ' #发送带附件的邮件 msgRoot = のMimeMultipart() msgRoot.attach(ます:MIMEText(コンテンツ、' HTML '、' UTF-8 ' )) msgRoot [ ' 件名' ] = 主題 msgRoot [ ' から' ] = 送信元 #msgRootは[ 'と']受信= msgRoot [ ' に' ] = ' ' .join(受信) msgRoot.attach(ATT) #Eメール SMTP = smtplib.SMTP_SSL(SmtpServerは、465 ) #1 サーバは、ユーザID識別SMTPを。 HELO(SmtpServerは) #のサーバーは、結果が確認返しsmtp.ehlo(SmtpServerは) #のログメールサーバのユーザ名と認証コードsmtp.login(SENDER、パスワード) #送信メールsmtp.sendmail(SENDER、受信、msgRoot.as_string()) SMTPを。終了()印刷(「送信成功」)