0

请耐心等待我是 ASP.NET 的新手。这是我所做的,

网页配置

<system.net>
  <mailSettings>
   <smtp from="mygmail@gmail.com">
   <network host="smtp.gmail.com" password="mygmailpwd" 
     userName="mygmail@gmail.com" enableSsl="true"/>
   </smtp>
  </mailSettings>
</system.net>

PASSWORDRECOVERYRES.ASPX

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="PasswordRecoveryRes.aspx.cs" Inherits="PasswordRecovery" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h1> Forgot Your Password?</h1>
    <asp:PasswordRecovery ID="PasswordRecovery1" runat="server" 
        onsendingmail="PasswordRecovery1_SendingMail" 
        onsendmailerror="PasswordRecovery1_SendMailError" 
        onverifyinganswer="PasswordRecovery1_VerifyingAnswer" 
        onverifyinguser="PasswordRecovery1_VerifyingUser">
        <MailDefinition From="mygmail@gmail.com" Subject="Password Recovery">
        </MailDefinition>
    </asp:PasswordRecovery>
</asp:Content>

PASSWORDRECOVERYRES.ASPX.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class PasswordRecovery : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {

  }
  protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
  {
      PasswordRecovery1.SuccessText = e.Message.Body;
      e.Cancel = true;
  }
  protected void PasswordRecovery1_SendMailError(object sender, SendMailErrorEventArgs e)
  {

  }
  protected void PasswordRecovery1_VerifyingAnswer(object sender, LoginCancelEventArgs e)
  {

  }
  protected void PasswordRecovery1_VerifyingUser(object sender, LoginCancelEventArgs e)
  {

  }
}

当我运行 PASSWORDRECOVERYRES.ASPX 时,我没有收到任何错误。显示以下消息

"Please return to the site and log in using the following information. User Name: username1 Password: %#;IXWh3b:Zj$:"

但是这条消息不应该从 mygmail@gmail.com 通过电子邮件发送到 username1@gmail.com 吗?我究竟做错了什么?

4

2 回答 2

1

在您的 SendingMail 事件 ( PasswordRecovery1_SendingMail) 中,您首先将邮件正文复制到控件,然后取消该事件(这会阻止发送电子邮件)。

令人惊讶的是,这两个操作是您背后代码中唯一的用户代码,您仍然会问为什么它不起作用。它的工作原理与您实现它的方式完全相同。注释这两行代码,你很可能会得到想要的效果。

于 2012-09-26T17:46:54.843 回答
0

参考这个网址:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.passwordrecovery.aspx

protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
    PasswordRecovery1.SuccessText = "Mail Sent Successfully!!";
}
于 2012-09-27T18:39:00.673 回答