4

I need to send an email using python and to bypass the TITUS CLASSIFICATION pop-up that comes up with the current script. The pop-up stops it from auto sending.

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

I have a VBA solution to auto send the email, but it would be easier and more intuitive to have everything in the PYTHON script rather than creating a VBA macro and calling it.

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

Any help greatly appreciated!

Ariel
  • 928
  • 4
  • 15
  • 32
  • do you really need `Outlook` to send mails ? Can't you use `smtplib` to send directly. – furas Dec 06 '16 at 20:46
  • I tried smtplib but received an error when connecting to the server, it would be more useful to use outlook – Ariel Dec 06 '16 at 20:53

2 Answers2

1

This should do it for you.

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

See this link for more details.

Sending mail from Python using SMTP

Community
  • 1
  • 1
ASH
  • 20,759
  • 19
  • 87
  • 200
1

Add the below code to end of send function and it selects TITUS Classification:

mailUserProperties  = newMail.UserProperties.Add("gmail.comClassification", 1)
mailUserProperties.Value = "For internal use only" 
newMail.Display() 
newMail.Send()
Ariel
  • 928
  • 4
  • 15
  • 32
  • 1
    This answer seems to be working with "gmail.comClassification" which does not work with the custom TITUS add-on. Any idea how to set the classification properties of those? – Konstantin Sep 06 '19 at 15:06
  • 1
    Code not able to handled TITUS classification pop-up box in OUTLOOK mail – Ravi K Jan 10 '20 at 08:02