send email using python in ubuntu

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
import datetime
import pytz
import time
import sys
tz_NY = pytz.timezone('Asia/Kolkata')
x = datetime.datetime.now(tz_NY)
# list of email_id to send the mail
li = ["adityaypi@yahoo.com", "rcmaditya@gmail.com","adityaypi@live.com","aditya@peakecorp.com"]
msg = MIMEMultipart()
msg['From'] = "aditya@peakecorp.com"
x = datetime.datetime.now(tz_NY)
for dest in li:
 try:
    subject = 'Admin Notofication'+ x.strftime('%m/%d/%Y %H:%M:%S')+" "+dest
    msg['To'] = dest
    msg['Subject'] = subject
    body = 'Latest FI Prices '+x.strftime('%m/%d/%Y %H:%M:%S')+' Attached'
    msg.attach(MIMEText(body,'html'))
    text = msg.as_string()
    s = smtplib.SMTP('smtp.gmail.com', 587)
    s.starttls()
    s.login("aditya@peakecorp.com", "app password")
    s.sendmail("", dest, text)  
    s.quit()
    time.sleep(1)
 except Exception as e:
    sys.stderr.write(str(e)+'\n')
    sys.stderr.flush()

Discover more from Soa Technology | Aditya Website Development Designing Company

Subscribe to get the latest posts sent to your email.



Leave a Reply

Discover more from Soa Technology | Aditya Website Development Designing Company

Subscribe now to keep reading and get access to the full archive.

Continue reading