0

I'm using angularjs 1.4.8 in Visual Studio 2013. I want to send email to xxxx@ xxxx.com with message "Your registration completed" automatically after button has been clicked. How can I send email by angularjs?

  [HttpPut]
    [Route("api/SendMail")]
    protected void sendmail()
    {

        var fromAddress = "[email protected]";
        var toAddress = "[email protected]";
        const string fromPassword = "workufs1234";
        MailMessage mailMessage = new MailMessage(fromAddress, toAddress);
        mailMessage.To.Add(toAddress);
        mailMessage.Subject = "Documents";
        string messge = "hellooooo";
        string tempmsg = "";
        var messg = @"<html><body><br />Dear  ss ,<br /><br />  <br />";
        mailMessage.To.Add(toAddress);
        string html = messg.ToString();
        AlternateView altView = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html);
       MailMessage mail = new MailMessage();
        mailMessage.AlternateViews.Add(altView);
        mailMessage.Body = messg.ToString();
        mailMessage.IsBodyHtml = true;

        SmtpClient mailSender = new SmtpClient("162.222.225.82"); //use this if you are in the development server
        mailSender.Host = "smtp.gmail.com";
        mailSender.Port = 587;
        mailSender.EnableSsl = true;
        mailSender.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        mailSender.Credentials = new NetworkCredential(fromAddress, fromPassword);
        mailSender.Timeout = 40000;
        mailSender.Send(mailMessage);
    }

How can test this using postman. is this httppost or put or?

1
  • You will have to do that functionality from API side because in device you can only open mail composer with all details filled but you will have to press send button manually i. e. not automatic. Commented Jul 18, 2016 at 12:12

2 Answers 2

0

HTML code:

<button ng-click="sendMail()"></button>

Controller:

$scope.message = {} // contact info goes here

$scope.sendMail = function(){
  var mail = 'mailto:[email protected]?subject=' + $scope.message.name +
               '&body=' + $scope.message.content;
  $window.open(mail);
}
Sign up to request clarification or add additional context in comments.

1 Comment

not need window. i want send automatically send mail
0

I think you will need a server side to do this properly. (PHP / NodeJS, ...)

On my NodeJS server, I'm using 'nodemailer', which works perfectly. https://www.npmjs.com/package/nodemailer

Hope it helps.

2 Comments

i' m use angularjs not use nodejs
Yes, but AngularJS is only running on the client side. You also need a server side to launch your application from a server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.