除了这个帖子send outlook mail via win32com之外,我想知道是否有可能使用mail.From
类似的方法。创建电子邮件时,您可以选择要发送的电子邮件。
对于未来,我从哪里可以获得这些信息?我的意思是这些命令是否适用于outlook应用程序的COM对象?
答案 0 :(得分:1)
这是我长期使用的代码,希望对你有用,
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders
def sendMail(to, subject, text):
assert type(to)==list
fro = "abc@xyz.com" # use your from email here
msg = MIMEMultipart()
msg['From'] = fro
msg['To'] = COMMASPACE.join(to)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach(MIMEText(html, 'html'))
smtp = smtplib.SMTP('mailhost.abcd.co.in') #use your mailhost here, it's dummy.
smtp.sendmail("", to, msg.as_string() )
smtp.close()
TOADDR = ['abc@xyz.com'] # list of emails address to be sent to
html = """\
<html>
<head></head>
<body>
<p>Hi!<br>
How are you?<br>
Here is the <a href="http://www.python.org">link</a> you wanted.
</p>
</body>
</html>
"""
sendMail( TOADDR, "hello",html)