Python 发送带有 TITUS 分类的 outlook 邮件

标签 python vba excel email

我需要使用 python 发送电子邮件并绕过当前脚本随附的 TITUS 分类弹出窗口。弹出窗口会阻止它自动发送。

python

olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "My Subject"
newMail.Body = "My Body"
newMail.To  = "myemail@gmail.com"
newMail.send()

VBA

我有一个自动发送电子邮件的 VBA 解决方案,但是将所有内容都放在 PYTHON 脚本中比创建 VBA 宏并调用它更容易和更直观。

Dim AOMSOutlook As Object
Dim AOMailMsg As Object
Set AOMSOutlook = CreateObject("Outlook.Application")
Dim objUserProperty As Object
Dim OStrTITUS As String
Dim lStrInternal As String
Set AOMailMsg = AOMSOutlook.CreateItem(0)

Set objUserProperty = AOMailMsg.UserProperties.Add("TITUSAutomatedClassification", 1)
objUserProperty.Value = "TLPropertyRoot=ABCDE;Classification=For internal use only;Registered to:My Companies;"
With AOMailMsg
  .To = "myemail@gmail.com"
  .Subject = "My Subject"
  .Body = "My Body"
  .Send
End With

Set AOMailMsg = Nothing
Set objUserProperty = Nothing
Set AOMSOutlook = Nothing
Set lOMailMsg = Nothing
Set objUserProperty = Nothing
Set lOMSOutlook = Nothing

非常感谢任何帮助!

最佳答案

这应该为您完成。

SMTPserver = 'smtp.att.yahoo.com'
sender =     'me@my_email_domain.net'
destination = ['recipient@her_email_domain.com']

USERNAME = "USER_NAME_FOR_INTERNET_SERVICE_PROVIDER"
PASSWORD = "PASSWORD_INTERNET_SERVICE_PROVIDER"

# typical values for text_subtype are plain, html, xml
text_subtype = 'plain'


content="""\
Test message
"""

subject="Sent from Python"

import sys
import os
import re

from smtplib import SMTP_SSL as SMTP       # this invokes the secure SMTP protocol (port 465, uses SSL)
# from smtplib import SMTP                  # use this for standard SMTP protocol   (port 25, no encryption)

# old version
# from email.MIMEText import MIMEText
from email.mime.text import MIMEText

try:
    msg = MIMEText(content, text_subtype)
    msg['Subject']=       subject
    msg['From']   = sender # some SMTP servers will do this automatically, not all

    conn = SMTP(SMTPserver)
    conn.set_debuglevel(False)
    conn.login(USERNAME, PASSWORD)
    try:
        conn.sendmail(sender, destination, msg.as_string())
    finally:
        conn.quit()

except Exception, exc:
    sys.exit( "mail failed; %s" % str(exc) ) # give a error message

有关详细信息,请参阅此链接。

Sending mail from Python using SMTP

关于Python 发送带有 TITUS 分类的 outlook 邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41004496/

相关文章:

python - tensorflow 在 anaconda 控制台中工作,在笔记本中失败,显示 :. ModuleNotFoundError:没有名为 'tensorflow' 的模块

excel - 用于根据过滤行从选项卡复制数据的宏

excel - 当中值计算为零时崩溃(程序没有响应)(VBA)

vba - 如何仅在过滤的数据/可见单元格上应用 vlookup 公式

python - 限制redis python中zrangbycore函数的最小最大值?

python - 在迭代所有形式时选择正确的形式

python - 为什么这段获取 Airflow 上下文的代码会在 DAG 导入时运行?

excel - 如何在excel中找到隐藏的字符

vba - 使 VBA DateDiff 的行为和 Excel DATEDIF 一样向下舍入

r - 如何从 R 中将 Excel 工作表范围导出到图片