【问题标题】:expire confirmation email after 48 hour in asp.net在 asp.net 中 48 小时后过期的确认电子邮件
【发布时间】:2012-12-15 19:20:55
【问题描述】:

我向我的用户发送确认email,当他们点击它时,他们的帐户将变为活动状态。 我唯一想要的是在 48 小时后使链接失效,并且用户可以使用该username 再次注册。有谁能够帮我? 这是我的电子邮件代码:

   Session["UserName"] = TextBox_email.Text;

   MailMessage msg = new MailMessage();
   StringBuilder bodyMsg = new StringBuilder();

   MembershipUser user = Membership.CreateUser(TextBox_email.Text, TextBox_Pass.Text, TextBox_email.Text);

   Roles.AddUserToRole(TextBox_email.Text, "Author");
   user.IsApproved = false;
   Membership.UpdateUser(user);

 //  StringBuilder bodyMsg = new StringBuilder();

   Guid userID = (Guid)user.ProviderUserKey;


   msg.Subject = "Submission Confirmation";
   bodyMsg.Append("<html><head><img src=" + "http://waag.ir/images/header.jpg" + ">" + "<title>CONFIRMATION EMAIL:</title></head><body>");
   bodyMsg.Append("<br/>");
   string link = string.Format("http://www.waag.ir/Activate.aspx?userID={0}", userID.ToString());
   bodyMsg.Append("Dear " + RadioButtonList_Prefix.SelectedItem.Text + " " + name.Text + " " + middle.Text + " " + lastname.Text + ":<br> Thank you for registering with Avestia Publishing manuscript submission system. To confirm and complete your registration, please follow the link below:</br>" + link + "</br>This link is active for 48 hours. If the link is not visited within this time frame, your registration will be discarded and you will need to register again.</br></br></br>Best regards,</br>Avestia Publishing</br>http://avestia.com");

   msg.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
   msg.Priority = MailPriority.High;

   msg.Body = bodyMsg.ToString();
   msg.IsBodyHtml = true;
   msg.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
   msg.Priority = MailPriority.High;

   //  msg.ReplyTo = new MailAddress(TextBox2.Text);
   msg.From = new MailAddress("goldenstudio@goldenstudio.ir");
   msg.To.Add(new MailAddress(TextBox_email.Text));
   SmtpClient mailsender = new SmtpClient();

   mailsender.Host = "SmtpClient.goldenstudio.ir";

   mailsender.Port = 587;
   mailsender.EnableSsl = true;
   mailsender.Credentials = new System.Net.NetworkCredential("goldenstudio@goldenstudio.ir", "classaspnet");

   SmtpClient smtp = new SmtpClient();
   //Literal1.Text = "<script>alert(' ')</script>";
   smtp.Send(msg);

【问题讨论】:

  • 您应该更改您的电子邮件密码。
  • 您的电子邮件不是问题,您需要一种机制来使其过期。您已经为它生成了一个唯一的密钥,现在只需保存它在某处创建的日期/时间并针对它进行验证。

标签: asp.net email confirmation-email


【解决方案1】:

在您的Users 表(我假设您有一个)中添加一个名为ConfirmationDueDate 的列,并将其设置为从用户单击OK 创建帐户后的48 小时。当用户点击链接时,如果当前时间超过ConfirmationDueDate值,则将其带回帐户创建页面。

【讨论】:

    【解决方案2】:

    您需要在数据库中记录电子邮件的发送时间,然后将该日期与用户单击链接的日期进行比较。因此,例如,您在 2012 年 12 月 31 日 18:22 发送电子邮件,而我在 2013 年 1 月 1 日 18:22 点击链接,则只有 1 天。

    您需要将逻辑构建到存储过程或在检查 DateSent 字段的确认页面上运行的 asp.net 代码中

    编辑
    您可以通过使其仅在特定日期之前有效来“过期”链接。如果用户在该日期之后尝试使用该链接,则您将其视为已过期并显示相关消息。但是您需要将日期存储在数据库中,在我最初的建议中,我说过要存储您发送电子邮件的日期(在 DateSent 字段中)并与之进行比较,另一个答案建议设置链接到期的日期(在ExpiryDate 字段)。这两种方法都行得通,它们只是从问题的不同端来解决问题。

    【讨论】:

    • 谢谢...有什么方法可以在不点击的情况下使链接失效。我的意思是我们可以为此使用计时器吗?
    • @SaeedTalaee:链接不是这样工作的。没有“过期”的 URL 这样的东西。相反,您可以让 URL 处的代码返回错误。
    【解决方案3】:

    您需要在数据库中记录电子邮件的发送时间,然后将该日期与用户单击链接的日期进行比较。因此,例如,您在 2012 年 12 月 31 日 18:22 发送电子邮件,而我在 2013 年 1 月 1 日 18:22 点击链接,则只有 1 天。

    您需要将逻辑构建到存储过程或在检查 DateSent 字段的确认页面上运行的 asp.net 代码中

    编辑 您可以通过使其仅在特定日期之前有效来“过期”链接。如果用户在该日期之后尝试使用该链接,则您将其视为已过期并显示相关消息。但是您需要将日期存储在数据库中,在我最初的建议中,我说过要存储您发送电子邮件的日期(在 DateSent 字段中)并与之进行比较,另一个答案建议设置链接到期的日期(在ExpiryDate 字段)。这两种方法都行得通,它们只是从问题的不同端来解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      • 1970-01-01
      • 2013-08-17
      • 2016-03-03
      • 2020-08-16
      • 2017-10-25
      • 2017-07-02
      相关资源
      最近更新 更多