• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    Python
  • Created over 7 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📧 Automated Customized Emails Using Python

Sending Multiple Customized Emails Using Gmail API & Python

This repository is dedicated to show:

  • How to use Python Gmail API.
  • How to send multiple automated emails with customized features.

https://github.com/astorfi/Send-Multiple-Emails/blob/master/_img/source.gif

Motivation

There are couple of questions as motivate someone to use the python API for sending customized gmail.

  • What if you want to send a fixed email to multiple people at once?
  • What if you want to send multiple emails to a certain individual at once?
  • What if you want to send multiple emails to multiple people?
  • What if you want to almost similar emails to multiple people with only changing the subject or greeting customized by their first name?

Consider the aformentioned variations, using an API to easily change the email format and content using a predefined pattern or a parsed text is of great interest. As an example, let's consider we have a .csv file which has multiple subjects with their information. Suppose we want to parse the .csv file and send an invitation email to each individual when only the initial part of the emails is different which is Dear X or Dear Y for example. Using a python interface can make life easy and come to rescue us. In this repository, the exact aforementioned example will be addressed.

Bigger picture

At first time the python script opens a browser to take and store Gmail credentials locally. Then by using another script, the message creation will be performed. We basically use the codes provided by google except we customize few things to parse the .csv file and write the email format.

Run the Gmail API, Installation and authorization

At first, the Gmail API must be initialized. Please refer to this link. After turning on the Gmail API, the Google Client Library must be installed by executing the following in the command line:

pip install --upgrade google-api-python-client

After installation, the file code/quicksetup.py must be run for providing the credentials locally. Remember the file client_secret.json must be provided and it could be downloaded when the Gmail API is being turned.

Send customized email

Now the interface is ready to go. Let's take a look and our main file code/sendmessage.py. It is the code at here with some minor changes. We parse the .csv file and send customized emails.

Take a look at the context of the sample .csv file:

FirstName,LastName,EmailAddress,Company,Position
subject_name,subject_lastname,subject_email,X Corporation,Sr. Deep Learning,

The .csv file can contain multiple lines of different individuals of information. We parse it as follows:

def sendmail(attribute):
    first_name = attribute[0]
    last_name = attribute[1]
    email = attribute[2]
    print("Sending email to {}".format(email))

    to = email
    sender = "[email protected]"
    subject = "subject"
    msgPlain = ""
    msgHtml = "Hi {},<br/>This is a test email".format(first_name)
    SendMessage(sender, to, subject, msgHtml, msgPlain)


 def main():
   with open("file.csv", "rb") as file:
        msg_reader = csv.reader(file)
        msg_reader.next()
        map(sendmail, msg_reader)

So for each individual email, we just change the name and sent it again. That's all. Seems super easy but the problem is easy when it is solved, right?

Final Note

Before using this codes, first just provide a simple .csv file or whatever file you want to parse, and use only your emails to make sure nothing is messed up. because the last thing you want is to send wrong emails to multiple people.

More Repositories

1

TensorFlow-World

🌎 Simple and ready-to-use tutorials for TensorFlow
Python
4,532
star
2

Deep-Learning-Roadmap

📡 Organized Resources for Deep Learning Researchers and Developers
Python
3,164
star
3

lip-reading-deeplearning

🔓 Lip Reading - Cross Audio-Visual Recognition using 3D Architectures
Python
1,763
star
4

speechpy

💬 SpeechPy - A Library for Speech Processing and Recognition: http://speechpy.readthedocs.io/en/latest/
Python
879
star
5

3D-convolutional-speaker-recognition

🔈 Deep Learning & 3D Convolutional Neural Networks for Speaker Verification
Python
764
star
6

Deep-Learning-NLP

📡 Organized Resources for Deep Learning in Natural Language Processing
Python
433
star
7

CNTK-World

🌎 Simple and ready-to-use deep learning examples for the Microsoft Cognitive Toolkit (CNTK)
Python
329
star
8

3D-convolutional-speaker-recognition-pytorch

🔈 Deep Learning & 3D Convolutional Neural Networks for Speaker Verification
Python
123
star
9

sequence-to-sequence-from-scratch

💬 Sequence to Sequence from Scratch Using Pytorch
Python
120
star
10

QR_Code

QR Code Pattern Recognition and Message Extraction
TeX
52
star
11

cor-gan

🔓 COR-GAN: Correlation-Capturing Convolutional Neural Networks for Generating Synthetic Healthcare Records
Python
51
star
12

attention-guided-sparsity

Attention-Based Guided Structured Sparsity of Deep Neural Networks
Python
29
star
13

TensorFlow-World-Resources

📡 Organized & Useful Resources about Deep Learning with TensorFlow
Python
21
star
14

Large-Scale-AI-Blueprint

A comprehensive guide designed to empower readers with advanced strategies and practical insights for developing, optimizing, and deploying scalable AI models in real-world applications.
20
star
15

Caffe_Deep_Learning

Python
14
star
16

differentially-private-cgan

Python
11
star
17

Create-LMDB-from-Numpy

Python
7
star
18

auto-punctuation-pytorch

Jupyter Notebook
6
star
19

gan-evaluation

Python
4
star
20

Data-Structures-and-Algorithms

C++
4
star
21

Local-Histogram-Equalization

Python
4
star
22

OpenCV-Installation

Shell
3
star
23

Leethcode

Python
3
star
24

ML-workflow

Python
2
star
25

deep-clustering-kmeans

Python
1
star
26

LeetCode

Python
1
star
27

audio-diffusion-tutorial

Exploring audio generation through diffusion models
Jupyter Notebook
1
star
28

blog-tutorials

Jupyter Notebook
1
star