Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Need Outlook send email code using python
Hi All,

Is there any working code for sending email in python using Outlook 365?
I tried different codes which I found in google but nothing is working as expected. Please share code.

Thank you in advance.

Please share your code snippet and detail us the difficulty you are facing.
Hi Malt,

Here is the code

import win32com.client as win32

Outlook = win32.Dispatch('Outlook.application')
mail = Outlook.CreateItem(0)
mail.To = ''
mail.Subject = 'python test'
mail.Body = 'test'
mail.HTMLBody = '<h2>HTML Message body</h2>'
When I run tis script I am getting below error

Traceback (most recent call last): File "C:\Users\Sri\PycharmProjects\PythonCoding\venv\lib\site-packages\win32com\client\", line 89, in _GetGoodDispatch IDispatch = pythoncom.connect(IDispatch) pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/Sri/PycharmProjects/PythonCoding/venv/", line 3, in <module> Outlook = win32.Dispatch('Outlook.application') File "C:\Users\Sri\PycharmProjects\PythonCoding\venv\lib\site-packages\win32com\client\", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Users\Sri\PycharmProjects\PythonCoding\venv\lib\site-packages\win32com\client\", line 114, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Users\Sri\PycharmProjects\PythonCoding\venv\lib\site-packages\win32com\client\", line 91, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2146959355, 'Server execution failed', None, None)
buran wrote Jul-01-2020, 03:54 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to send email using python? Gigux 2 232 Jul-04-2020, 07:53 AM
Last Post: Gigux
  I am trying to send an email with python nick235 9 328 Jun-29-2020, 06:40 PM
Last Post: nick235
  reading shared outlook emails zarize 0 226 Mar-03-2020, 01:47 PM
Last Post: zarize
  Help Needed | Read Outlook email Recursively & download attachment Vinci141 0 366 Feb-21-2020, 04:45 AM
Last Post: Vinci141
  smtlib send email without logging in codeathoffenmer 1 420 Nov-28-2019, 03:41 PM
Last Post: DeaD_EyE
  Is this possible in Python? Auto-Send-to-printer on script run? pcsailor 8 4,882 Jul-19-2019, 09:33 AM
Last Post: perfringo
  Reading email messages on Outlook johnjohn 9 20,585 Apr-03-2019, 10:41 AM
Last Post: Ken2702
  Code Wireless Temperature sensor and send sensor readings to google sheet jenkins43 0 701 Nov-29-2018, 12:44 PM
Last Post: jenkins43
  How to Find a specific email in Outlook with Python Code jassi123 2 1,357 Oct-31-2018, 08:07 AM
Last Post: jassi123
  [Outlook] How to delete items from To-Do List? Winfried 1 820 Oct-19-2018, 09:05 PM
Last Post: nilamo

Forum Jump:

Users browsing this thread: 1 Guest(s)