Reputation: 13
I'm trying to send html emails using win32com.client. Here's a sample code:
import win32com.client as win32
mail = win32.Dispatch('outlook.application').CreateItem(0)
mail.To = '[email protected]'
mail.Subject = 'test'
mail.HTMLBody = html_pages
mail.Send()
My solution now is to upload the images to a server and insert the urls into html_pages. The drawback is that the images are not displayed when the server is down. Is there a way to send the images with the emails using win32com?
Upvotes: 1
Views: 19490
Reputation: 1530
One way to do that would be sending images as an attachment:
import win32com.client as win32
mail = win32.Dispatch('outlook.application').CreateItem(0)
mail.To = '[email protected]'
mail.Subject = 'test'
mail.HTMLBody = html_pages
attachment = '*path to your image*'
mail.Attachments.Add(attachment)
mail.Send()
Or you can put image in the html body:
import win32com.client as win32
mail = win32.Dispatch('outlook.application').CreateItem(0)
mail.To = '[email protected]'
mail.Subject = 'test'
mail.HTMLBody = html_pages + <br><img src="path">
mail.Send()
Or if you want the image actually attached to the body and not being linked to a path, have a look here:
Upvotes: 2