一尘不染

从AngularJS Web应用程序发送电子邮件

angularjs

在我的AngularJS
Web应用程序之一中,我需要通过向相关人员发送电子邮件来确认密码。如何在AngularJS中实现呢?我是.NET专家,正在使用Visual Studio
2013。


阅读 479

收藏
2020-07-04

共1个答案

一尘不染

我已经通过网络服务实现了,请参考下面的代码片段

public bool EmailNotification()
    {
            using (var mail = new MailMessage(emailFrom, "test.test.com"))
            {
                string body = "Your message : [Ipaddress]/Views/ForgotPassword.html";
                mail.Subject = "Forgot password";
                mail.Body = body;
                mail.IsBodyHtml = false;
                var smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.EnableSsl = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new NetworkCredential(emailFrom, emailPwd);
                smtp.Port = 587;
                smtp.Send(mail);
                return true;
            }
    }

和ajax调用为

 $.ajax({
        type: "POST",
        url: "Service.asmx/EmailNotification",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data)
        {

        },
        error: function (XHR, errStatus, errorThrown) {
            var err = JSON.parse(XHR.responseText);
            errorMessage = err.Message;
            alert(errorMessage);
        }
    });
2020-07-04