【问题标题】:Change "from" field option in outlook using python via win32com通过 win32com 使用 python 在 Outlook 中更改“来自”字段选项
【发布时间】:2013-12-10 10:36:26
【问题描述】:

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

【问题讨论】:

  • 我不知道是否可以使用 win32com 但这可以使用 smtplib 来完成。
  • @VIKASH JAISWAL,您能否提供可能的解决方案或提出想法,谢谢!

标签: python outlook win32com


【解决方案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)

【讨论】:

  • 感谢您的回复。 IMAP/POP 服务器是否有任何偏好?
  • 因为我从未使用过类似的东西所以不知道,但我看到还有其他库。例如看这个链接:stackoverflow.com/questions/18156485/…
猜你喜欢
  • 2014-08-18
  • 2021-05-11
  • 1970-01-01
  • 1970-01-01
  • 2021-06-24
  • 1970-01-01
  • 1970-01-01
  • 2023-02-08
  • 1970-01-01
相关资源
最近更新 更多