mhammond / pywin32

Python for Windows (pywin32) Extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error sending Outlook email after upgrade to Office 365

damoboyle opened this issue · comments

Note that issues in this repository are only for bugs or feature requests in the pywin32.

If you need support or help using this package, please follow these instructions - support or help requests will be closed without comment.

For all bugs, please provide the following information.

  • Expected behavior and actual behavior.

  • Steps to reproduce the problem.

  • Version of Python and pywin32


I have been using the below code for over a year with no issue. It pulls up outlook and automatically sends emails where they need to go. After a recent upgrade to Office 365 Applications from Office 2016 Applications the code is suddenly failing, but only when it tries to send mail, it works perfectly fine when displaying or saving as a draft.

import win32com.client as win32

def email(address, subject, message, attach=[]):

#Open Outlook and compose an email
outlook = win32.Dispatch('Outlook.Application')
mail outlook.CreateItem(0)

mail. To address
mail.Subject = subject

#Pulls up default signature of sender from Outlook
mail.GetInspector

#HTML text to inform receiver that this email is automated
intro "<i style='color:red'>This is an automated message.</i><br><br>"

#Used to merge intro and user message into HTML body properly while including default signature
Index = mail.HTMLbody.find('>', mail.HTMLbody.find('<body'))

mail.HTMLbody = mail.HTMLbody[:index + 1] + intro + message + mail.HTMLbody[index + 1:]

#Attach File
if attach:
    for file in attach:
        mail.Attachments.Add(file)

#Send Email
#mail Display(True) #Displays Email for Testing
#mail.Save() #Save as Draft
mail.Send()

Traceback Error:

File "C:\Users\me\Documents\python\win_email.py", line 29, in email

mail.Send()

File "", line 2, in Send

pywintypes.com_error: (-2147024809, 'The parameter is incorrect.', None, None)

See the very first 2 lines of your issue text.