Python发送带有TITUS分类的Outlook电子邮件
问题描述:
我需要使用python发送电子邮件并绕过当前脚本提供的TITUS CLASSIFICATION弹出窗口。弹出窗口阻止它自动发送。Python发送带有TITUS分类的Outlook电子邮件
PYTHON
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "My Subject"
newMail.Body = "My Body"
newMail.To = "[email protected]"
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 = "[email protected]"
.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
任何帮助非常感谢!
答
添加下面的代码来结束发送功能,并且它选择TITUS分类:
mailUserProperties = newMail.UserProperties.Add("gmail.comClassification", 1)
mailUserProperties.Value = "For internal use only"
newMail.Display()
newMail.Send()
答
这应该为你做。
SMTPserver = 'smtp.att.yahoo.com'
sender = '[email protected]_email_domain.net'
destination = ['[email protected]_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
查看此链接了解更多详情。
你真的需要'Outlook'发送邮件?你不能用'smtplib'直接发送。 – furas
我试过smtplib,但连接到服务器时收到错误,使用outlook会更有用 – Ariel