-2

我正在使用 ASP NET 4.0 通过HttpHandlerOr发送电子邮件的首选方式是什么web service?谢谢。

4

3 回答 3

2

您应该在服务器端代码上发送电子邮件。如果您通过 HttpHandler 或 Web 服务公开邮件 API,您的系统将被垃圾邮件发送者用作中继服务器。

于 2013-02-25T16:05:20.113 回答
1

是的,正如@peer 所建议的那样,这是一个坏主意。提醒密码(敏感操作)应该被安全地考虑和实施(请注意,我什至没有提到对它们进行散列)

我想您要实现的目标是让用户知道已向他们发送了一封电子邮件,而他们在提交电子邮件后没有刷新页面,对吗?如果是这样,您可以通过网络服务将电子邮件发送到处理您的代码的服务器端代码,并将密码发送到您的电子邮件地址。然后,您可以让该函数返回 true 或 false 以让用户知道“已发送包含您的密码的电子邮件”或“在我们的系统中未找到此类电子邮件”。

更新

说你有一个RemindPassword.aspx如下;

<script>
$(document).ready(function () {
   $.ajax({
 type: "POST",
 data: "{'email':'" + $('#txtEmail').val() + "'}",
 url: 'RemindPassword.aspx/sendEmail',
 contentType: "application/json; charset=utf-8",
 success: function (msg) {
  isok = JSON.parse(msg.d);
      msgelem = $('#results');
      if (isok == true) {
        msgelem.html('your password has been sent to your email.')
      } else {
        msgelem.html('this email address does not exist in our system.')
      }
 }
})
   };
});

</script>

<asp:TextBox ID="txtEmail" runat="server" />
<asp:Button ID="btnSubmit" runat="server" Text="Send password.."/>
<span id="results"></span>

在 RemindPassword.aspx.vb 中:

导入 System.Web.Services

<WebMethod()> _
Public Shared Function SendMail(email As String) As Boolean
    ' write code here to check if email exists.
    ' if it does, run code (or another function) to send the password.
    ' then return true
    ' if the email doesnt exist, then return false.
End Sub
于 2013-02-25T16:26:19.327 回答
-1

您可以使用网络服务传输消息,但不会传递任何凭据。您可以从 javascript 调用 websercice。如果您需要代码,我可以提供帮助。

正文、抄送、密件抄送、主题所有这些细节都可以使用 javascript 传递给 webmethod。所有其他凭据都应保存在您的服务器代码中。

    function SendMail(txtTo, txtFrom, txtCC, txtBCC, txtSubject, txtMessage)

 {     


     // call server side method

     PageMethods.sendmail(txtTo, txtFrom, txtCC, txtBCC, txtSubject, txtMessage);

 }



 // set the destination textbox value with the ContactName

 function CallSuccess(res)

 {     

         alert(res) ;
 }



 // alert message on some failure

 function CallFailed(res)

 {

     alert(res.get_message());

 }

在服务器上

public static void SendMail(string txtTo, string txtFrom, string txtCC, string txtBCC, string txtSubject, string txtMessage)
{
try
    {

        //Creating the Mail Message object.
        MailMessage Email=new MailMessage();
        //Storing the To value in the object reference.
        Email.To=txtTo;                
        //Storing the From value in the object reference.
        Email.From=txtFrom;
        //Storing the CC value in the object reference.
        Email.Cc=txtCC;
        //Storing the BCC value in the object reference.
        Email.Bcc=txtBCC;
        //Storing the Subject value in the object reference.
        Email.Subject=txtSubject;
        //Specifies the email body.
        Email.Body=txtMessage;
        //Setting priority to the mail as high,low,or normal
        Email.Priority=MailPriority.High;
        //Formatting the mail as html or text.
        Email.BodyFormat=MailFormat.Text;
        //Checking whether the attachment is needed or not.
        //if(rbtnAttach)
        //{
        //    //Adding attachment to the mail.
        //    Email.Attachments.Add(
        //        new MailAttachment(FileBrowse));
        //}
        //specifying the real SMTP Mail Server.
        SmtpMail.SmtpServer.Insert(0,"127.0.0.1");
        SmtpMail.Send(Email);//Sending the mail.
        //calling the reset method to erase all the data 
        //after sending the mail.

    }
    //Catching Exception 
    catch(Exception exc)
    { 

    }

}

更多详情,您可以参考:

http://www.dotnetcurry.com/ShowArticle.aspx?ID=109 http://www.codeproject.com/KB/aspnet/Techblaster/Techblaster_demo.zip

于 2013-02-25T16:24:13.077 回答