我在smtp中得到了来自字段的奇怪显示,email.The显示就像;
出发地: test@gmail.com To: test@gmail.com,Subject: Message test@gmail.com to:
“字段”为空白,但另一个“收件人”( test1@gmail.com成功地接收到了电子邮件)。下面是我的密码。
import smtplib
def SendEmailScenario1():
gmail_user = "test@gmail.com"
gmail_password = '******'
sent_from = gmail_user
to = ["test1@gmail.com"]
subject = 'Message'
body = "Hi There! Done1"
email_text = """\
From: %s
To: %s
Subject: %s
%s
""" % (sent_from, ", ".join(to), subject, body)
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(sent_from, to, email_text)
server.close()
print ('Email sent!')
except:
print ('Something went wrong...')
def SendEmailScenario2():
gmail_user = "test@gmail.com"
gmail_password = '******'
sent_from = gmail_user
to = ["test1@gmail.com"]
subject = 'Message'
body = "Hi There! Done 2"
email_text = """\
From: %s
To: %s
Subject: %s
%s
""" % (sent_from, ", ".join(to), subject, body)
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(sent_from, to, email_text)
server.close()
print ('Email sent!')
except:
print ('Something went wrong...')
SendEmailScenario1()
SendEmailScenario2()如何在不使用MIMEText、MIMEMultipart的情况下将其正常显示
https://stackoverflow.com/questions/64174931
复制相似问题