【问题标题】:Python send outlook email with TITUS classificationPython 发送带有 TITUS 分类的 Outlook 电子邮件
【发布时间】:2017-04-21 15:08:57
【问题描述】:

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

蟒蛇

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

非常感谢任何帮助!

【问题讨论】:

  • 您真的需要Outlook 来发送邮件吗?不能用smtplib直接发送吗?
  • 我尝试了smtplib,但连接服务器时收到错误,使用outlook会更好用

标签: python vba excel email


【解决方案1】:

这应该为你做。

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

【讨论】:

    【解决方案2】:

    将以下代码添加到发送函数的末尾并选择 TITUS 分类:

    mailUserProperties  = newMail.UserProperties.Add("gmail.comClassification", 1)
    mailUserProperties.Value = "For internal use only" 
    newMail.Display() 
    newMail.Send()
    

    【讨论】:

    • 这个答案似乎适用于“gmail.comClassification”,它不适用于自定义 TITUS 插件。知道如何设置它们的分类属性吗?
    • 代码无法处理 OUTLOOK 邮件中的 TITUS 分类弹出框
    猜你喜欢
    • 2015-05-03
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 2017-02-04
    相关资源
    最近更新 更多