When sending an email with the code below, the result is not as expected. There's a missing image AND the template is not centered as should be. I provide what exists vs what is expected. I'm not sure if the problem is in the HTML
or the reading of the template.
python code:
import smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
class Mail:
def __init__(self):
self.sender_mail = 'someone@gmail.com'
self.password = 'my_pw'
self.smtp_server_domain_name = "smtp.gmail.com"
self.port = 465
def send(self, emails):
ssl_context = ssl.create_default_context()
service = smtplib.SMTP_SSL(self.smtp_server_domain_name, self.port, context=ssl_context)
service.login(self.sender_mail, self.password)
for email in emails:
mail = MIMEMultipart('mixed')
mail['Subject'] = 'Celebrations'
mail['From'] = self.sender_mail
mail['To'] = email
html_file = open('./templates/index.html')
html_content = MIMEText(html_file.read(), 'html')
mail.attach(html_content)
service.sendmail(self.sender_mail, email, mail.as_string())
service.quit()
if __name__=='__main__':
mail = Mail()
mail.send(emails=['you@gmail.com'])