Just as shown below, currently I have already implemented sending HTML format email using Outlook 2010 and python
def send_mail_via_com(self):
o = win32com.client.Dispatch("Outlook.Application")
Msg = o.CreateItem(0)
Msg.To = self.myEmailAddress
Msg.BCC = self.myEmailAddress
Msg.Subject = 'This is Subject'
Msg.HTMLBody = htmlEmailContent
Msg.Send()
Going forward, I want to show some embed images in the HTML format email, I've check the the HTML source, it looks like following:
<img border=0 width=117 height=20 id="Picture_x0020_2" src="cid:[email protected]" alt="Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: cid:[email protected]">
I tried to attached the image files(using the same name referenced in above html codes as attachment) but it will just be attachment and won't be shown in the text body as embed image. Our mail serve doesn't support SMTP protocol, so I cannot use the smtplib as that in Sending Multipart html emails which contain embedded images. Can somebody help me out? thanks in advance!
attachment1 = "G:\\image001.png"
Msg.Attachments.Add(attachment1)
2013/8/8 Update, I got a C# version codes via http://social.msdn.microsoft.com/Forums/vstudio/en-US/6c063b27-7e8a-4963-ad5f-ce7e5ffb2c64/how-to-embed-image-in-html-body-in-c-into-outlook-mail, could anybody show me Python counterpart codes for these:
Attachment attachment = newMail.Attachments.Add(
@"E:\Pictures\image001.jpg"
, OlAttachmentType.olEmbeddeditem
, null
, "Some image display name"
);
string imageCid = "image001.jpg@123";
attachment.PropertyAccessor.SetProperty(
"http://schemas.microsoft.com/mapi/proptag/0x3712001E"
, imageCid
);
newMail.HTMLBody = String.Format(
"<body><img src=\"cid:{0}\"></body>"
, imageCid
);