-
-
Save garymanley/40279ee89b99b8a32ab53fa4cd315cff to your computer and use it in GitHub Desktop.
Outlook HTML E-mail
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
# -*- 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.HtmlBody = (r"""Hi One and all,<br> <br> | |
Summary data is shown below. <br><br> | |
<style type="text/css"> | |
.tg {border-collapse:collapse;border-spacing:0;} | |
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:3px 20px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;} | |
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:3px 20px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;} | |
.tg .tg-vkco{font-weight:bold;font-size:11px;font-family:Arial, Helvetica, sans-serif !important;;background-color:#f59614;vertical-align:top} | |
.tg .tg-kl7f{font-size:11px;font-family:Arial, Helvetica, sans-serif !important;;vertical-align:top} | |
.tg .tg-mer2{font-size:11px;font-family:Arial, Helvetica, sans-serif !important;;text-align:right;vertical-align:top} | |
.tg .tg-4n4u{font-size:11px;font-family:Arial, Helvetica, sans-serif !important;;background-color:#82378c;color:#cbcefb;vertical-align:top} | |
.tg .tg-8i5d{font-weight:bold;font-size:11px;font-family:Arial, Helvetica, sans-serif !important;;background-color:#f59614;text-align:right;vertical-align:top} | |
.tg .tg-s1pv{font-weight:bold;font-size:11px;font-family:Arial, Helvetica, sans-serif !important;;background-color:#82378c;color:#cbcefb;vertical-align:top} | |
</style> | |
<table class="tg"> | |
<tr> | |
<th class="tg-4n4u"><br> <br> </th> | |
<th class="tg-s1pv"><br> Column1<br> </th> | |
<th class="tg-s1pv"><br> Column2<br> </th> | |
<th class="tg-s1pv"><br> Column3<br> </th> | |
</tr> | |
<tr> | |
<td class="tg-kl7f"> Start of week<br> </td> | |
<td class="tg-mer2">"""+'5,000'+"""<br> </td> | |
<td class="tg-mer2">"""+'5,000'+"""<br> </td> | |
<td class="tg-mer2">"""+'10,000'+"""<br> </td> | |
</tr> | |
<tr> | |
<td class="tg-kl7f">Change in week<br> </td> | |
<td class="tg-mer2">"""+'500'+"""<br> </td> | |
<td class="tg-mer2">"""+'500'+"""<br> </td> | |
<td class="tg-mer2">"""+'1,000'+"""<br> </td> | |
</tr> | |
<tr> | |
<td class="tg-vkco">Number Now<br> </td> | |
<td class="tg-8i5d">"""+'5,500'+"""<br> </td> | |
<td class="tg-8i5d">"""+'5,500'+"""<br> </td> | |
<td class="tg-8i5d">"""+'11,000'+"""<br> </td> | |
</tr> | |
<tr> | |
<td class="tg-kl7f">Total next month<br> </td> | |
<td class="tg-mer2">"""+'10,000'+"""<br> </td> | |
<td class="tg-mer2">"""+'5,000'+"""<br> </td> | |
<td class="tg-mer2">"""+'15,000'+"""<br> </td> | |
</tr> | |
<tr> | |
<td class="tg-kl7f">Total Leaving next month<br> </td> | |
<td class="tg-mer2">"""+'1,000'+"""<br> </td> | |
<td class="tg-mer2">"""+'1,000'+"""<br> </td> | |
<td class="tg-mer2">"""+'2,000'+"""<br> </td> | |
</tr> | |
<tr> | |
<td class="tg-vkco">Net Change in month <br> </td> | |
<td class="tg-8i5d">"""+'9,000'+"""<br> </td> | |
<td class="tg-8i5d">"""+'4,000'+"""<br> </td> | |
<td class="tg-8i5d">"""+'13,000'+"""<br> </td> | |
</tr> | |
<tr> | |
<td class="tg-vkco">Est next month<br> </td> | |
<td class="tg-8i5d">"""+'14,500'+"""<br> </td> | |
<td class="tg-8i5d">"""+'9,500'+"""<br> </td> | |
<td class="tg-8i5d">"""+'24,000'+"""<br> </td> | |
</tr> | |
</table> | |
<br><br> | |
Thanks, <br> <br> | |
""" | |
) | |
################################## | |
### 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