0

我想跟踪阅读过我邮件的用户。我正在这样做,但它不起作用我在 Outlook 中向自己发送邮件。这是我发送邮件的代码

  try
        {

        string emailTemplateBody = "Hy this is test mail";
        emailTemplateBody += "<tr><img src=''http://localhost:52583/HttpModule_using_beacon_images/images/<keyvalue>.aspx''  style=''opacity:0.0; filter:alpha(opacity=0);'' /></tr>";



        string templateName = txtTemplateName.Text;

                    string toEmail = mymailaddress

        //// Get unique Key after registring mail to be sent
        string key = bl_email_calls.RegisterSystemEmailAudit("1", templateName, DateTime.Now);
        emailTemplateBody = emailTemplateBody.Replace("<keyvalue>", key);
        //// sending e-mail
        bl_email_calls.SendMailMessage(toEmail, templateName, emailTemplateBody, key);
        using (var cn = new SqlConnection(ConfigurationManager.ConnectionStrings["webConnectionString"].ToString()))
        {
           //code to insert record in database;            }
        Response.Write("Mail sent");
        // return false;
    }
    catch (Exception ex)
    {

        throw;
    }

这是我从 http://www.aspnetemail.com/samples/emailtracker/default.aspx[^] 使用的 HTTP 模块

public class HttpModuleClass : IHttpModule
{
    //public event EventHandler BeginRequest;

    public void Dispose()
    {

    }

    /// <summary>
    /// public varibles
    /// </summary>
    string footerFile = "~/images/footer.png";
    //string footerFile = "~/images/ajax-loader.gif";
    Email_Calls bl_email_calls = new Email_Calls();

    /// <summary>
    /// Init methoed
    /// </summary>
    /// <param name="context"></param>
    public void Init(HttpApplication context)
    {
        context.BeginRequest += new System.EventHandler(GetImage_BeginRequest);
    }

    /// <summary>
    /// handles requests made to server and call update email read time
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="args"></param>
    public void GetImage_BeginRequest(object sender, System.EventArgs args)
    {
        //cast the sender to a HttpApplication object
        System.Web.HttpApplication application = (System.Web.HttpApplication)sender;

        string url = application.Request.Path; //get the url path
        //string pattern = @"/HttpModule/images/(?<key>.*)\.aspx";
        //string pattern = @"/HttpModule_using_beacon_images/images/(?<key>.*)\.aspx";

        string pattern = @"/HttpModule_using_beacon_images/images/(?<key>.*)\.aspx";
        //string pattern = @"~/images/(?<key>.*)\.aspx";
        //create the regex to match for beacon images
        Regex r = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
        if (r.IsMatch(url))
        {
            MatchCollection mc = r.Matches(url);
            if ((mc != null) && (mc.Count > 0))
            {
                string key = (mc[0].Groups["key"].Value);
                bl_email_calls.UpdateSystemEmailAuditReadDate(key);

            }

            //now send the REAL image to the client
            //application.Response.ContentType = "image/gif";
            application.Response.ContentType = "image/png";

            application.Response.WriteFile(application.Request.MapPath(footerFile));

            //end the response
            application.Response.End();
        }
    }
}
4

2 回答 2

2

要请求已读回执,我们需要添加'Disposition-Notification-To' 在此示例中命名的自定义标头,已读回执将返回到“someaddress@mydomain.com”。重要的是要注意,已读回执只会由那些支持它们的邮件客户端发送b) 启用它们。

//添加"Disposition-Notification-To"已读回执

  mail.Headers.Add("Disposition-Notification-To", "<mail@yahoo.com>");
于 2012-06-11T11:59:55.247 回答
0

我知道了。我犯了一些小错误。

实际上,我正在将电子邮件正文保存到数据库中,所以我不得不使用''而不是,'这很麻烦。当被删除''它工作正常。

于 2012-06-12T03:52:29.683 回答