2016-12-06 10 views
3

私はpythonを使用してメールを送信し、現在のスクリプトに付属するTITUS CLASSIFICATIONポップアップをバイパスする必要があります。ポップアップは自動送信からそれを停止します。むしろVBAマクロを作成するよりも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

私はautoにVBAソリューションを持っている電子メールを送信するが、Pythonスクリプトですべてを持っているために、より簡単かつ直感的になりますし、それを呼び出す。

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 

大変助かりました!

+0

は、あなたが本当にOutlook'がメールを送信するために '必要がありますか? 'smtplib'を使って直接送ることはできません。 – furas

+0

smtplibを試しましたが、サーバーに接続する際にエラーが発生しました。Outlookを使用するとより便利になります – Ariel

答えて

1

送信機能の最後に以下のコードを追加し、それがTITUS分類を選択:

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

これはあなたのために行う必要があります。

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 

詳細については、このリンクを参照してください。

Sending mail from Python using SMTP

関連する問題