Python smtplib ''Subject'' 为什么它不打印任何主题。我现在几乎什么都试过了
Python smtplib ''Subject'' why doesn't it print any subject. I've tried almost anything now
电子邮件发送代码工作正常,没有问题,但它会在消息字段中打印所有内容。在过去的 3 个小时里,我基本上已经尝试了一切。有什么建议吗?
import smtplib
fromaddr="xxxxx@xxx.com"
toaddr="xxxxx@xxxx.com"
message = '''\
... From: xxxxx
... Subject: testin'...
...
... This is a test '''
password="xxxx"
subject="this is supposed to be the subject"
server=smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(fromaddr,password)
server.sendmail(fromaddr,toaddr,message,subject)
server.quit()
subject = "this is supposed to be the subject"
使用 MIMEText 创建消息对我来说一直很有效。
以下是您的使用方法:
import smtplib
from email.mime.text import MIMEText
# message body goes here
message = '''\
... This is a test '''
msg = MIMEText(message, 'plain')
msg['Subject'] = "this is supposed to be the subject"
msg['From'] = "xxxxx@xxx.com"
msg['To'] = "xxxxx@xxxx.com"
server=smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(fromaddr,password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
希望对您有所帮助!
电子邮件发送代码工作正常,没有问题,但它会在消息字段中打印所有内容。在过去的 3 个小时里,我基本上已经尝试了一切。有什么建议吗?
import smtplib
fromaddr="xxxxx@xxx.com"
toaddr="xxxxx@xxxx.com"
message = '''\
... From: xxxxx
... Subject: testin'...
...
... This is a test '''
password="xxxx"
subject="this is supposed to be the subject"
server=smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(fromaddr,password)
server.sendmail(fromaddr,toaddr,message,subject)
server.quit()
subject = "this is supposed to be the subject"
使用 MIMEText 创建消息对我来说一直很有效。 以下是您的使用方法:
import smtplib
from email.mime.text import MIMEText
# message body goes here
message = '''\
... This is a test '''
msg = MIMEText(message, 'plain')
msg['Subject'] = "this is supposed to be the subject"
msg['From'] = "xxxxx@xxx.com"
msg['To'] = "xxxxx@xxxx.com"
server=smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(fromaddr,password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
希望对您有所帮助!