Skip to content

Instantly share code, notes, and snippets.

@garymanley
Created December 31, 2017 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garymanley/df73d5dbd007c7daf0fdd1e8eda24cc1 to your computer and use it in GitHub Desktop.
Save garymanley/df73d5dbd007c7daf0fdd1e8eda24cc1 to your computer and use it in GitHub Desktop.
OutlookBasicSend.py
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 30 16:56:13 2017
@author: garym
"""
#import win32com.client
from win32com.client import Dispatch
import datetime
import win32com.client
########################################
### Set up file to attach
########################################
filename = r'C:\Users\garym\Documents\New folder (2)\CV.docx'
########################################
## Connect to Outlook inbox
#########################################
outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
# "6" refers to the index of a folder. 6 is the inbox
inbox = outlook.GetDefaultFolder("6")
### all inbox for today after 7am
#####################
### Craete new Email
#####################
const=win32com.client.constants
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
##################################
##Mail content
##################################
newMail.Subject = "Hello World - " + str(datetime.datetime.today().strftime('%d/%m/%Y'))
newMail.Attachments.Add(filename)
newMail.Body = "Hello World"
##################################
### Set recipients to maillist
#################################
newMail.To = 'my@email.com'
newMail.CC = 'my@email.com'
################################
## Show E-mail (change to send to send)
################################
newMail.display()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment