Reputation: 200
I am trying to use the win32 Python library to send some emails, but I am unable to specify the sensitivity label in an automatic way. As soon as I try to send out the email by using the below code, the Azure Information Protection dialog box pops up making this impossible to automate.
As I understood from reading various articles, there might be a workaround specifying the GUID string, but I have no idea how to do it.
I would really appreciate if you could help me out!
outlook = win32com.client.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]'
mail.Subject = 'Sample Email'
mail.HTMLBody = '<h3>This is HTML Body</h3>'
mail.Body = "This is the normal body"
mail.Sensitivity = 3
mail.Send()
Upvotes: 3
Views: 2894
Reputation: 27
(FYI I was going to add the below as comment above but my reputation is too low so just adding this here)
I was having the same problem as above with setting the Sensitivity level also not working. I found a workaround via another site and re-posted the solution/ workaround in the below stackoverflow question that I originally looked at before seeing this one.
In short, you create a outlook template with the sensitivity already set, and then call that via outlook.CreateItemFromTemplate instead of outlook.CreateItem(0), example python code as follows:
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItemFromTemplate(r"C:\Users\email_template.oft", )
mail.To = 'email'
mail.Subject = 'subject'
mail.Body = 'Message body'
mail.Send()
Sending emails using outlook with Python - Overcoming Azure Information Protection Classifications
Upvotes: 0
Reputation: 1
You could try this code instead.
import win32com.client as win32
olApp =win32.Dispatch("Outlook.Application")
olNS=olApp.GetNameSpace("MAPI")
mailItem= olApp.CreateItem(0)
mailItem.Subject="Hello my friend2"
mailItem.BodyFormat=1
mailItem.Body="This is the body of the email"
#mailItem.BodyFormat=2
#mailItem.HTMLBody="<HTLM Markup>"
mailItem.To="[email protected]"
#The numbers in the Invoke function do not change that
mailItem._oleobj_.Invoke(*(64209,0,8,0,olNS.Accounts.Item("[email protected]")))
mailItem.Display()
mailItem.Save()
mailItem.Send()
Be careful with the OlItemType enumeration the OlItemType enumeration and OlBodyFormat Enum.
Have a good one!
Upvotes: 0