gpt4 book ai didi

python - 当邮件打开时收到消息

转载 作者:太空宇宙 更新时间:2023-11-04 03:49:28 25 4
gpt4 key购买 nike

从下面的代码中,我正在发送带有一些信息的邮件。这里我需要将消息发送到我的邮件 ID,当他/她打开邮件时。如何在 Python 中执行此操作。

def Data(request):
templateName = "sendmail.html"
mapDictionary = {'fromMail': "xxxx.xxxx@gmail.com", 'password': "xxxxx", 'toMail': "yyyyy.yyyy@gmail.com@gmail.com",
"subject": "New Trip Confirmation", 'username': 'Ramesh','trip_start_date' : '2014-02-10',
'trip_start_place' : 'Visak', 'trip_start_time' : '11:00 AM', "templateName" : templateName
}
print ("call send mail from processNewTripData...")
return sendmail(request, mapDictionary)


def sendmail(request, mapDictionary):
try:
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login(mapDictionary["fromMail"],mapDictionary["password"])
context = Context(mapDictionary)
html_content = render_to_string(mapDictionary["templateName"], context)
#text_content = "This is Confirmation mail"
msg = MIMEText(html_content,'html')
msg['Subject'] = mapDictionary["subject"]
server.sendmail(mapDictionary["fromMail"], mapDictionary['toMail'], msg.as_string())
to_json = {'result' : "True"}
return HttpResponse(simplejson.dumps(to_json), content_type='application/json')
except Exception as e:
print str(e)
to_json = {'result' : "False"}
return HttpResponse(simplejson.dumps(to_json), content_type='application/json')

最佳答案

尝试添加这个标题:

Disposition-Notification-To: "User" <user@user.com>

读者可能需要确认您是否收到回复。此外,添加由您的服务器提供的 html 内容可以作为一种识别邮件已读的选项。

您应该能够使用这些行中的任何一行来执行此操作

msg['Disposition-Notification-To'] = '"User" <user@user.com>'
msg['Disposition-Notification-To'] = 'user@user.com'

关于python - 当邮件打开时收到消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21983515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com