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
Py-Contributors / 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
git clone https://github.com/codePerfectPlus/PyEmailer
cd PyEmailer
from src.send_email import PyEmailer
your_email_id = "your_email_id"
your_app_password = "your_app_password"
email_subject = "email_subject_here"
email_content = "<h1> Email Content can be html too</h1>"
listOfEmail = ["destination1@gmail.com", "destination2@gmail.com"]
pyemail = PyEmailer(your_email_id, your_app_password)
if __name__ == "__main__":
pyemail.sendEmail(email_subject, email_content, listOfEmail)
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/
Top comments (1)
Source code
codePerfectPlus / Email-Sending-Script-Python
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