I am trying to automate a report and send it by mail daily. I would like to have images / graphs embedded in my mail.
My program currently generates graphs and saves them on my Destok so I can then join them to my mail with yagmail. I pass a list of HTML lines as strings in a "body" variable to generate the mail. I then extend my HTML body to scale it for every studied subject automatically.
Issue : the graphs do not show on mobile. I think a good option would be to add something in my HTML mail body like CSS : img {max-height : 100 %;} but can't figure how to do it with my current method.
I tried to use a mail service provider (mailjet) but could not customize my mail as I wished (ex: loop through text and images).
Hope someone can help.
My mail code :
#receivers as a list
receivers = ["abcdef@gmail.com",
"ghijkl@gmail.com"
]
#date
now=datetime.now() #record current moment
date_mail=str(now.strftime('%d%m%Y'))+ " (ddmmYYYY)" #format as daymonthyear + add some text + all as text => will be in mail header
#Identification
yagmail.register("my_sender_mail@gmail.com", "password_me") #register to yagmail / gmail adress + application password
yag = yagmail.SMTP("my_sender_mail@gmail.com") #define mail
#mail body
body = ["<p>Hello,</p>", #will be merged for every analysis / is a list !
"<p>Please find below your daily ......</p>",
"<p>Our method combines different strategies to ..... </p>",
"<p>If we are not confident enough accross multiple methods ....</p>",
"<p>If a method yields poor result it will not be displayed on the graphs.</p>",
"<br>", #input a line
"<p>If the graphs do not show properly please allow your mailbox to ""download"" images for this sender.</p>",
"<p>Please do not hesitate to contact us to ....</p>",
"<br>",
"<p><b>"+str(tickers[0])+" </b></p>", # first ticker in the body
"<p>Daily signal: "+ mail_decision[0] +" </p>", # first decision for the ticker
"<p>Graph :</p>",
"""<img src="C://Users//tangu//OneDrive//Bureau//image_"""+str(0)+"""_complete.png" width="700" height="450">""", #embed main graph for the whole period, set width (issue!) and height
"""<img src="C://Users//tangu//OneDrive//Bureau//image_"""+str(0)+"""_reduced.png" width="700" height="450">""" #embed the reduced graph for a short term view, set width (issue!) and height
]
for i in range(1,len(tickers)): #extend the body for every strategy
body_to_app=["<p><b>"+str(tickers[i])+" </b></p>", #ticker in the body
"<p>Daily signal: "+ mail_decision[i] +" </p>", #decision for the ticker
"<p>Graph :</p>",
"""<img src="C://Users//tangu//OneDrive//Bureau//image_"""+str(i)+"""_complete.png" width="700" height="450">""", #embed main graph for the whole period, set width (issue!) and height
"""<img src="C://Users//tangu//OneDrive//Bureau//image_"""+str(i)+"""_reduced.png" width="700" height="450">""", #embed the reduced graph for a short term view, set width (issue!) and height
]
body.extend(body_to_app) #extend (/"merge") the list
#add best regards
body.extend(["<p>Best Regards,<p>"])
#loop through recievers
for receiver in receivers: #for element in recievers
#send the mail
yag.send(
to=receiver,
subject="Subject at date : _ "+str(date_mail),
contents=body
)