Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在邮件打开时获取消息_Python_Email - Fatal编程技术网

Python 在邮件打开时获取消息

Python 在邮件打开时获取消息,python,email,Python,Email,根据下面的代码,我正在发送带有一些信息的邮件。在这里,当他/她打开邮件时,我需要将邮件发送到我的邮件id。 如何在Python中实现这一点 def Data(request): templateName = "sendmail.html" mapDictionary = {'fromMail': "xxxx.xxxx@gmail.com", 'password': "xxxxx", 'toMail': "yyyyy.yyyy@gmail.com@gmail.com",

根据下面的代码,我正在发送带有一些信息的邮件。在这里,当他/她打开邮件时,我需要将邮件发送到我的邮件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'
msg['Disposition-Notification-To']='“User”'
msg['Disposition-Notification-To']='user@user.com'

是否有示例代码?如何使用处置通知:“用户”添加了最可能的示例。