DETAILS

Create the email sending program from Python

Create the email sending program from Python

Create the email sending program from Python with source code

To send an email using Python, you will need to use the smtplib library. This library comes with Python and can be imported using the following code: import smptlib

To send an email, you will need to have access to an SMTP (Simple Mail Transfer Protocol) server. Most email providers have an SMTP server that you can use to send emails from your email account. For example, if you have a Gmail account, you can use the SMTP server provided by Google to send emails from your Gmail account.

Following are the source code to create the eamil sending program from Python

import csv
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
 

email_sender = Your email
email_password = Your password
subject = "Write your subject here...."


with open('email.csv','r') as csv_file: ## opens and reads the csv files containing email address of receivers
    csv_reader = csv.reader(csv_file)
    for line in csv_reader: ## for loop for the emails on the csv files
        text="Hello, Greetings from OnlineNotesNepal"+line[1]+" Write your message here."
 

        send_email = line[0]
        msg = MIMEMultipart()
        msg['From'] = email_sender
        msg['To'] = send_email
        msg['Subject'] = subject
        msg.attach(MIMEText(text,"plain"))
        text = msg.as_string()

        server = smtplib.SMTP_SSL("smtp.gmail.com",465)
        server.login(email_sender,email_password)
        server.sendmail(email_sender,send_email,text)

        server.quit()