Created
January 27, 2015 01:08
-
-
Save maxint/42b8d80621ba02f2ee65 to your computer and use it in GitHub Desktop.
Send email through Outlook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32com.client | |
def send_mail_via_com(text, subject, recipient, profilename="Outlook2003"): | |
s = win32com.client.Dispatch("Mapi.Session") | |
o = win32com.client.Dispatch("Outlook.Application") | |
s.Logon(profilename) | |
Msg = o.CreateItem(0) | |
Msg.To = recipient | |
Msg.CC = "moreaddresses here" | |
Msg.BCC = "address" | |
Msg.Subject = subject | |
Msg.Body = text | |
attachment1 = "Path to attachment no. 1" | |
attachment2 = "Path to attachment no. 2" | |
Msg.Attachments.Add(attachment1) | |
Msg.Attachments.Add(attachment2) | |
Msg.Send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment