我想从"southrotaryclub@gmail.com"如gmail或hotmail,雅虎等几封电子邮件
然而,当我发送这个消息时。hotmail的单词已经变成了几个HTML文件,而不是真正的单词。当我从iphone上读到这封hotmail时,"address.png"的图片变成了随机数
有人知道如何缓解这些问题吗?我希望电子邮件包含明文文字和图片。
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)
尝试使用SMTP。它是一个标准的Python包。语法很简单。教程链接- https://www.youtube.com/watch?v=JRCJ6RtE3xU