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.