[Python] Send an email with outlook

Introduction

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.

Reference site

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()

Execution result

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

[Python] Send an email with outlook
[Automation] Send Outlook email with Python
Send email with Python
Send an email with Amazon SES + Python
Send Japanese email with Python3
Send email in Python (Outlook)
Send an email to Spushi's address with python
Send an email with Excel attached in Python
[Python] Send email
[Python] Send email
Note: Send an email with Django
Send email via gmail with Python 3.4.3.
[Python] Send an email from gmail with two-step verification set
HTML email with image to send with python
I tried sending an email with python.
Send email with Django
I tried sending an email with SendGrid + Python
What to do if you couldn't send an email to Yahoo with Python.
Send an email to a specific email address with python without SMTP settings
Creating an egg with python
Send using Python with Gmail
To automatically send an email with an attachment using the Gmail API in Python
[boto3] Send an email using SES
Cut out an image with python
I tried sending an email from Amazon SES with Python
[Automation] Extract Outlook appointments with Python
Create an Excel file with Python3
I sent an SMS with Python
Easy email sending with haste python3
Draw an illustration with Python + OpenCV
If you can't send an email with python smtplib and have trouble, command line
Send multipart / form-data with python requests
Send image with python, save with php
[Python] Building an environment with Anaconda [Mac]
Note when creating an environment with python
Quickly create an excel file with Python #python
[Python] Quickly create an API with Flask
Scraping from an authenticated site with python
Create an English word app with python
Join an online judge with Python 3.x
Let's develop an investment algorithm with Python 1
Python 3.6 email library
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Send email with SES in Python and short message with SMS on SNS
Twilio with Python
Play with 2016-Python
Tested with Python
with syntax (Python)
Bingo with python
[Outlook] I tried to automatically create a daily report email with Python
Excel with Python
Microcomputer with Python
Cast with python
Output the report as PDF from DB with Python and automatically attach it to an email and send it
Send a message to LINE with Python (LINE Notify)
Create an app that guesses students with python
[Python] Make a game with Pyxel-Use an editor-