How to send bulk email using python script

How to send bulk email using python script

Hello, to send bulk emails using email there is so many problem to send each person a seperate mail Instead you can use python to mail in bulk using few lines of code.

Here is the code for sending bulk emails using python.
Process:
  1. Import libraries
  2. Set SMTP server and post number which is the mail transfer protocol used to send and receive email across internet. Commonly 587 is the more suitable port for python.
  3. Now create a secure connection with server using starttls().
  4. Login on the previously created server using email_id and password.
  5. Now you can create a mail_list of the receivers which you want to send the mail or you can use external files to get mail_list of receivers.
  6. Create body of the mail you want to send.
  7. Set body as a message.
  8. Give appropriate Subject to the message which you want as a mail subject.
  9. Encode message into string.
  10. Now you are ready to send mail. Call send_mail() with parameters sender_mail_id by which you login and want to send mail, receiver_mail_id which can be a single person or a list of people and atlast message string.
  11. Now quit the server.



Code:
import smtplib
from email.mime.text import MIMEText
s = smtplib.SMTP("smtp.gmail.com", 587)
print("SMTP Server Created")
s.starttls()
print("TLS started")
s.login("sender_mail_id", "sender_password")
print("Login Successfully")
mail_list = ["mail1@gmail.com", "mail2@gmail.com", "mail3@gmail.com"]
body = """
<b>Congratulations!</b> You've successfully get scripted message.<br>
Go to the Google: <a href="https://www.google.com/">click here</a><br>
Thanks,<br>
<b>Divya Patel<b>
"""
msg = MIMEText(body, 'html')
msg['Subject'] = "DEMO, Scripted message!!"
text = msg.as_string()
s.sendmail("sender_mail_id", mail_list, text)
s.quit()

Advantage of this code:
  • E-mail is not going in spam folder.
  • You can send your message to bulk of emails in one run.

Thank You 

Post a Comment

0 Comments