使用python通过win32com更改outlook中的“from”字段选项

时间:2013-12-10 10:36:27

标签: python outlook win32com

除了这个帖子send outlook mail via win32com之外,我想知道是否有可能使用mail.From类似的方法。创建电子邮件时,您可以选择要发送的电子邮件。 对于未来,我从哪里可以获得这些信息?我的意思是这些命令是否适用于outlook应用程序的COM对象?

1 个答案:

答案 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)