通过python发送邮件
我一直在尝试从python向Outlook发送邮件。邮件中不显示正文。邮件被发送,带有主题。正文是空白的。可能是什么问题 这是我的密码:通过python发送邮件,python,email,outlook,Python,Email,Outlook,我一直在尝试从python向Outlook发送邮件。邮件中不显示正文。邮件被发送,带有主题。正文是空白的。可能是什么问题 这是我的密码: import smtplib username = "neooooo@example.com" password = "@death123" print("Logged in ") vtext = "nihjdoiwjadv@example.com" message = "this is the message t
import smtplib
username = "neooooo@example.com"
password = "@death123"
print("Logged in ")
vtext = "nihjdoiwjadv@example.com"
message = "this is the message to be sent"
msg = """From: %s
To: %s
Subject: Hi
Body:%s""" % (username, vtext, message)
print("Connecting to server")
server = smtplib.SMTP('smtp.office365.com',587)
server.starttls()
server.login(username,password)
server.sendmail(username, vtext, msg)
server.quit()
print("Done")
主体不是标题的一部分,尤其是没有称为主体的标题。邮件正文位于邮件头之后,用一个空行隔开。试试下面的代码。它对我有用
import smtplib,getpass,os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
os.system('clear')
msg=MIMEMultipart()
print "---------Python Mail Sender--------\n---------ONLY GMAIL Sender---------"
frm=raw_input("From : ")
to=raw_input("To : ")
msg['From']=frm
msg['To']=to
msg['Subject']=raw_input("Enter Subnject of mail : ")
text=raw_input("Enter text to send in mail : ")
msg.attach(MIMEText(text))
try :
mailserver=smtplib.SMTP("smtp.gmail.com",587)
mailserver.ehlo()
mailserver.starttls()
mailserver.ehlo()
mailserver.login(frm,getpass.getpass("Enter you password(Will not be visible as you Enter) : "))
mailserver.sendmail(frm,to,msg.as_string())
except Exception,e:
print "ERROR : ",e
finally:
mailserver.quit()
您是否尝试为
msg
分配一个简单字符串,例如msg='my test message'
?