0

I want to send messages from "southrotaryclub@gmail.com" to several emails like gmail or hotmail, yahoo etc.

However, when I send this message. the hotmail words have become several html files instead of real words. When I read this hotmail from my iphone, the picture of "address.png" became the random numbers.

Does anyone know how to mitigate those problems ? I want the email to contain plaintext words and the picture.

import numpy as np
import os
import pandas as pd
import csv
from string import Template
import smtplib
from pathlib import Path
from email import policy
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from google.colab import drive 

drive.mount('/content/drive')
df=pd.read_csv('/content/drive/MyDrive/inform_test.csv')
a=np.shape(df)
for k in range(0,a[0]):
   content = MIMEMultipart()  
   content["subject"] = "title"  
   content["from"] = "southrotaryclub@gmail.com"  
   content["to"] = df.iloc[k,1]
   content.attach(
                MIMEText(df.iloc[k,0],"html"))  
   main_content = "hello world" 
   content.attach(
                MIMEText(main_content,"html"))  
   content.attach(
                MIMEText("<br>","html"))  
   content.attach(
                MIMEText("<br>","html"))   
   content.attach(
                MIMEText("<br>","html"))   
   content.attach(
                MIMEText("phone","html"))                           
   content.attach(
                MIMEText("best regard","html")) 
   content.attach(MIMEImage(Path("/content/drive/MyDrive/mail_test/address.png").read_bytes()))
                        
   #print(k)
   with smtplib.SMTP(host="smtp.gmail.com", port="587") as smtp:  
      try:
          smtp.ehlo()  
          smtp.starttls()  
          smtp.login("southrotaryclub@gmail.com", "aasjwgeaymtajuks")  
          smtp.send_message(content)  
          print("successful")
      except Exception as e:
          print("Error message: ", e)
Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54

1 Answers1

0

Try using SMTP. It is a standard Python packages. And the syntax is pretty easy. Tutorial link - https://www.youtube.com/watch?v=JRCJ6RtE3xU