I made a macro to compose an email with excel at work "It's awkward to start with excel, and it's kind of like excel ..." If you look for it with a relaxed feeling because you are out of work I found a site that is easy to understand, so I made it.
https://towel-memo.com/python/email_python/
python
#Library
import win32com.client
#Outlook object settings
outlook = win32com.client.Dispatch('Outlook.Application')
mymail = outlook.CreateItem(0)
#signature
sign = '''
Hogehoge.com Co., Ltd.
Nabehiro of the world
'''
#Email settings
mymail.BodyFormat = 1
mymail.To = '[email protected]; [email protected]'
mymail.cc = '[email protected]'
mymail.Bcc = '[email protected]'
mymail.Subject = 'subject'
mymail.Body = '''Dear Sir
thank you for your hard work.
Thank you for your cooperation.
'''+ '\n' +sign
path = r'C:\\Users\watya\Desktop\hogehoge.txt' #Specify the attached file with an absolute path
mymail.Attachments.Add (path)
#Confirmation of completed email
mymail.Display(True)
#If you want to send without confirmation, mymail.Display(True)And use the code below
#mymail.Send()
mymail.Display(True) Since I ran it in, the email was created It wasn't sent and stopped in a draft state. Easy. .. .. This is useful for composing emails according to the template.
Moreover, from uses the Outlook address at login, so It's very easy because you don't have to be aware of it when creating a program. This is convenient!
Recommended Posts