Recently, chat-based communication tools such as LINE have become mainstream.
However, according to the "Business Email Survey 2020" of the Japan Business Email Association, ** "email" (99.1%) ** is the number one main means of communication used at work.
Since my company is "email culture", I exchange all kinds of information by email.
The most troublesome thing is [Email software bug status to team members every evening] That is.
Isn't there a lot of clerical work in every company that ** emails similar information to similar members on a regular basis **?
This kind of mechanical work is the most effective for automation.
Let's see the concrete method immediately.
According to the "Business Email Survey 2020" mentioned earlier, "Outlook" (50.52%) and "Gmail" (38.40%) are the two strongest email software used at work.
Therefore, in this article, I will introduce how to compose an email in Outlook.
You need to import win32com.client to operate outlook. I'm using Anaconda and I was able to import it without any additional installation.
python
import win32com.client
Next, create an Outlook object.
python
outlook = win32com.client.Dispatch("Outlook.Application")
And then create a mail object.
python
mail = outlook.CreateItem(0)
By changing the n part of CreateItem (n)
, you can create various items such as Outlook mail and calendar. Set to 0 to create an email object.
By setting attributes to this mail object, we will create a mail.
attribute | meaning |
---|---|
mail.to | destination |
mail.cc | CC |
mail.bcc | BCC |
mail.subject | subject |
mail.bodyFormat | Email format 1: Text 2:HTML 3: Rich text |
mail.body | Text |
python
mail.to = '[email protected]; [email protected]'
mail.cc = '[email protected]'
mail.bcc = '[email protected]'
mail.subject = 'Level 1 exam'
mail.bodyFormat = 1
mail.body = '''thank you for your hard work. This is Doremi.
It seems that this year's exam was a remote interview due to the influence of Corona.
I just heard from Majolica.
I was surprised, so I will contact you as soon as possible.
Thank you.
'''
We recommend that you check the emails you have created so far before sending them.
To check, use mail.display (True)
.
python
mail.display(True)
The email will open like this, so check it and send it if it's OK.
We hope that you will be freed from the hassle of sending emails. Finally, I will put the code together.
python
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application")
mail = outlook.CreateItem(0)
mail.to = '[email protected]; [email protected]'
mail.cc = '[email protected]'
mail.bcc = '[email protected]'
mail.subject = 'Level 1 exam'
mail.bodyFormat = 1
mail.body = '''thank you for your hard work. This is Doremi.
It seems that this year's exam was a remote interview due to the influence of Corona.
I just heard from Majolica.
I was surprised, so I will contact you as soon as possible.
Thank you.
'''
mail.display(True)
This time we introduced you to automating Outlook email sending, but see this article for how to read Outlook emails in Python. https://qiita.com/konitech913/items/fa0cf66aad27d16258c0
Recommended Posts