Send mail using SES AWS Python

Posted on by Sumit Kumar

import pandas as pd
from pretty_html_table import build_table
import boto3
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

ACCESS_KEY = ‘AKIATHOPBKF35ELXFTFX’
SECRET_KEY = ‘2RWyaUCXusLDx/aVUuiCyTBZfbj2b5D/IuuhfAm/’
ses = boto3.client(‘ses’, aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY,region_name=’us-east-1′)

def send_mail(df):
body = build_table(df, ‘blue_light’)
sender = “sumit8147085086@gmail.com”
to = ‘sumit8147085086@gmail.com’
cc = ‘sumit8147085086@gmail.com’
rcpt = cc.split(“,”) + to.split(“,”)
#rcpt = to.split(“,”)
message = MIMEMultipart()
message[‘Subject’] = “weather forecast mail”
message[‘From’] = sender
message[‘To’] = to
message[‘Cc’] = cc
body1 = “””

Hi All,

Below is the weather forecast data for next five days”””
#
body3=”””

Please login to portal – https://portal.deltafrog.com/ for additional information.

Regards,

DeltaFrog Team
“””
body_content = body1+body+body3
print(body_content)
# attachment_path = f
# fp = open(attachment_path,’rb’)
# x = fp.read()
# fp.close()
# attachment = MIMEApplication(x)
# attachment.add_header(“Content-Disposition”, “attachment”, filename=f.split(‘/’)[-1])
message.attach(MIMEText(body_content, “html”))
# message.attach(attachment)

msg_body = message.as_string()

ses.send_raw_email(Source = sender, Destinations = rcpt, RawMessage = {“Data”: msg_body})

mcol=[“Mon”,”Tuesday”,”wed”,”Thursday”,”Friday”]

data=[[‘H 90′,’H 88′,’H 84′,’H 87′,’H 86’],
[‘L 52′,’L 51′,’L 50′,’L 51′,’L 50’]]
df_forcast=pd.DataFrame(data,columns=mcol)
send_mail(df_forcast)

Posted in AWS.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*