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 = "xxxk@xxxxx.com";
        var toAddress = "rrrr@rrr.com";
        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?

Suny Saju
  • 165
  • 1
  • 2
  • 10
  • 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. – Hardik Vaghani Jul 18 '16 at 12:12

2 Answers2

0

HTML code:

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

Controller:

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

$scope.sendMail = function(){
  var mail = 'mailto:mohamed@labouardy.com?subject=' + $scope.message.name +
               '&body=' + $scope.message.content;
  $window.open(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.

Sparw
  • 2,688
  • 1
  • 15
  • 34