Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email from an AngularJS web application

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 using Visual Studio 2013.

like image 939
Ravi Shankar B Avatar asked Sep 10 '14 07:09

Ravi Shankar B


People also ask

Can I send email from Angular?

Without any server-side code hosted on a server, you can send emails through your Angular application with smtpJS, a client-side Javascript library. First you need to download this library and include it into the necessary component of the Angular Application.

Can we use AngularJS with ASP NET?

In this article, you will learn about AngularJS login form with ASP.NET. Learn to Create an empty MVC project, install Angular package, add Javascript Controllor, and add a Model class to the solution. As per you request, I am going to make a login page in AngularJS and ASP.

Can I use node js with AngularJS?

If you are writing an AngularJS front end web application, you may never have to use NodeJS. If you need tooling (build scripts to compile Sass, linters, etc) in your development or deployment process you can use NodeJS task runners like Gulp, Grunt or Webpack.

How do I send a front end email?

The mailto link is the easiest way to send an email from a front-end Javascript app. Put the email address you're sending to after mailto: as part of the string. When the user clicks on the anchor element, mailto will open the user's default email client and populate the “recipient” field with the intended email.


2 Answers

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);
        }
    });
like image 189
Ravi Shankar B Avatar answered Sep 30 '22 10:09

Ravi Shankar B


you cannot send email via javascript library (angularjs or jquery and so on) you need server side for send mail best way for this case use ajax

like image 36
Behnam Mohammadi Avatar answered Sep 30 '22 10:09

Behnam Mohammadi