0

I have this simple email script:

    import win32com.client as win32

    if __name__ == '__main__':
        outlook = win32.Dispatch('outlook.application')
        mail = outlook.CreateItem(0)
        mail.To = 'me@my_company.com'
        mail.Subject = 'test'
        mail.Body = 'Testing 1,2,3...'
        mail.Save()

This sample code works fine, as it does not raise an error and actually creates an email message in the Drafts folder of Outlook. Looking at te draft in Outlook itself, it also looks OK. But when I hit the Send-button, it goes wrong. I get an error message:

"IMCEAINVALID....encapsulated INVALID address inside an SMTP address"

Looking at the invalid address I see the following: "'me@my_company.com'"

So it looks like somewhere the single quotes are encapsulated by double quotes.

Using this: Verify Email Address using Outlook Global Address List in Python I verified 'me@my_company.com' exists in the GAL.

On the Internet I found a possible solution, namely in the options of Outlook clearing the Auto-complete cache: https://social.technet.microsoft.com/Forums/ie/en-US/c77100f9-5cd8-460b-a9e3-38dbea60dc95/outlook-2010-imceainvalid-ndr-with-exchange-2013?forum=exchangesvrclients

It does not work for me. Removing all contacts is not an option for me either.

Note that I cannot jump to other software like Aspose and Redemption, as suggested in: Create outlook draft email in python with out launching outlook application

Note that replacing mail.Save() with mail.Send() will actually send the email correctly.

Note that replacing:

    mail.To = 'me@my_company.com'

with:

    mail.Recipients.Add('me@my_company.com')

results in the same eror.

I use Python 3.6.6 (via PyCharm Community 2018.2) and Outlook 2016 with Exchange Server.

How do I end up with an email draft that is in the Drafts folder of Outlook, with the email address I intended it to have, so that later on I can actually send the email?

It may be solved on the side of Outlook, but if it can be fixed on the Python-side of the story that would be preferable.

MA53QXR
  • 82
  • 2
  • 11
  • Looks perfectly fine to me. What do you see in OutlookSpy if you select the message, click IMessage button, go to the GetRecipientTable tab, and look at the PR_EMAIL_ADDRESS and PR_ENTRYID properties/ – Dmitry Streblechenko Nov 22 '19 at 01:36
  • Sorry, but I cannot install software. Corporate rules... – MA53QXR Dec 19 '19 at 14:07
  • OutlookSpy does not require elevated rights - you can download the dll from http://www.dimastr.com/outspy/download.htm and register the dll with regsvr32.exe in any folder. – Dmitry Streblechenko Dec 19 '19 at 20:18

0 Answers0