Sending email from an AngularJS web application

前端 未结 4 1836
深忆病人
深忆病人 2020-12-31 14:14

In one of my AngularJS web applications, I need to confirm a password by sending emails to a concerned person. How can I achieve this in AngularJS? I am a .NET guy and I am

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-31 14:54

    I have achieved through web services Please refer the code snippet below

    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;
                }
        }
    

    and ajax call as

     $.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);
            }
        });
    

提交回复
热议问题