Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Member-only story

Automating Microsoft Outlook Email Sending in Python

Banana Chip Tech
Python in Plain English
6 min readNov 20, 2022

--

Using python to automate sending emails in MacOS

Photo by Brett Jordan on Unsplash

One of our most popular stories discussed how to automate sending emails using Python. In that article we used the smtplib library to connect to a SMTP server and send emails. While this was very useful, it had a few flaws. For one, we had to authenticate ourselves to the SMTP server through an email and password provided in a text based format in our code. Even though we took steps to ensure that our secret information was kept secret, this still represented a security major flaw in the program. Moreover, Google recently disabled the feature that allowed us to connect to the gmail SMTP server from less secure apps like ours, so we aren’t able to use this code for this use case anymore. Another issue with our previous approach was that it didn’t allow for email proofreading before sending.

As a workaround to these problems, in this article we wanted to talk about how to leverage appscripts and Python in MacOS to send personalized mass emails from Microsoft Outlook.

Pre-Reqs

Before getting into the details as to how this works, we first need to discuss certain pre-reqs that are required to run this program. First, you will need a computer with a MacOS operating system. While there are ways to do this in Windows or other operating systems, for the purposes of this article we will only focus on MacOS. Second, you will need to have Python and Xcode Command Line Tools installed. Third, you will need to have to Microsoft Outlook app downloaded to your computer and sign into your Outlook account. Emails will be sent from the default email that you set in this app. Finally, before we get into how to send emails using appscripts and Python, please make sure to review our previous article “Automate Sending Emails in Python” since we will be extending the class provided in that article to achieve new functionality.

Now that we have discussed the pre-requisites associated with this article, we need to make sure that we set the environment for this program to work. This involves making a template of the email that we would like to send and (optionally) getting the names and emails of people that need to be cc’d to all emails sent. The email template should use jinja template engine and be placed in…

--

--

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Written by Banana Chip Tech

Banana Chip Tech is focused on optimizing healthcare through computation! We build apps, create websites, and develop tech courses for healthcare professionals!

No responses yet

Write a response