DEV Community

loading...
Cover image for Send Web Email With Python Using Smtp and Google Account in bulk

Send Web Email With Python Using Smtp and Google Account in bulk

codeperfectplus profile image Deepak Raj ・1 min read

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}")
Enter fullscreen mode Exit fullscreen mode

Fork me here

GitHub logo codePerfectPlus / Email-Sending-Script-Python

Send Emails In One Click With Python.

Python 3.7 issues forks stars License

Visitor Count

header

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 variable

  • Step 2 Enter Email address in emaillist.py file.

  • Step 3 Run the Script

Project

footer

More Articles by Author

Join for Weekly Updates.

React ❤️ to encourage Author.

Discussion (1)

pic
Editor guide
Collapse
codeperfectplus profile image
Deepak Raj Author

Source code

GitHub logo codePerfectPlus / Email-Sending-Script-Python

Send Emails In One Click With Python.

Python 3.7 issues forks stars License

Visitor Count

header

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 variable

  • Step 2 Enter Email address in emaillist.py file.

  • Step 3 Run the Script

Project

footer