Python is a general multipurpose scripting language. It provides smtplib
module, which defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP or ESMTP listener daemon.
Here is a simple tutorial for sending an email using python. You can also integrate it with Flask/Django or other GUI framework for better presentation
import smtplib
import email.message
server = smtplib.SMTP('smtp.gmail.com:587')
email_content = "Message body"
listofemail = []
#Enter Email list here
msg = email.message.Message()
msg['Subject'] = 'Subject of Email'
msg['From'] = 'yourEmail@gmail.com'
password = "your gmail app password"
# create app password in accounts/security
msg.add_header('Content-Type', 'text/html')
msg.set_payload(email_content)
s = smtplib.SMTP('smtp.gmail.com: 587')
s.starttls()
# Login Credentials for sending the mail
s.login(msg['From'], password)
for dest in listofemail:
s.sendmail(msg['From'], dest, msg.as_string())
print(f"sending to {dest}")
Fork me here
codePerfectPlus
/
PyEmailer
Send Emails In One Click With Python.
Blog On Python, Machine Learning and Data Science Visit CodePerfectPLus
Create App Password in gmail.
- GO to Account setting/Security
- click app password
- Select APP -> others, Select Device -> Others
- Copy paste the code in script.py
password
variable
Usage
-
multipleSenderScript.py - Send Email to 1 person from different emails once.
-
multipleReceiver.py - Send Email to multiple person from one email(like: news Letter)
-
oneToOneEmail.py - Send one Email to one person at a time using command line tool
python oneToOneEmail.py destination@email.com
Reuirements
- python-fire
pip install fire
python -m pip install -r requirements.txt
Upcoming features
- file attachment in email
RegEx to verify the Emails
Project
- Project: PyEmailer
- Author: CodePerfectPlus
- Language: Python
- Github: https://github.com/codePerfectPlus
- Website: http://codeperfectplus.herokuapp.com/
More Articles by Author
- Build Your First Python Chatbot In 5 Minutes
- What is Simple Linear Regression?
- Logistic Regression for Machine Learning Problem
- 5 Tips for Computer Programming Beginners
- What Is Git and GitHub?
Top comments (1)
Source code
Send Emails In One Click With Python.
Send Emails In One Click With Python.
Step 1 Create App Password in gmail.
GO to Account setting/Security
click app password
Select APP -> others, Select Device -> Others
Copy paste the code in script.py
password
variableStep 2 Enter Email address in emaillist.py file.
Step 3 Run the Script
Project