Sending email from an AngularJS web application

前端 未结 4 1860
深忆病人
深忆病人 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:40

    You might also look into using a third party SaaS, like Mandrill, SendGrid, or MailGun. I have worked w/ building in an email feature using Mandrill. Account is free to setup and threshold for billing on messaging is like 12k/month. Sending is just a matter of following their API to HTTP POST to their REST interface. Small example below:

    .controller('sentMailCntrl',function($scope, $http){
      $scope.sendMail = function(a){
        console.log(a.toEmail);
        var mailJSON ={
            "key": "xxxxxxxxxxxxxxxxxxxxxxx",
            "message": {
              "html": ""+a.mailBody,
              "text": ""+a.mailBody,
              "subject": ""+a.subject,
              "from_email": "sender@sending.domain.com",
              "from_name": "Support",
              "to": [
                {
                  "email": ""+a.toEmail,
                  "name": "John Doe",
                  "type": "to"
                }
              ],
              "important": false,
              "track_opens": null,
              "track_clicks": null,
              "auto_text": null,
              "auto_html": null,
              "inline_css": null,
              "url_strip_qs": null,
              "preserve_recipients": null,
              "view_content_link": null,
              "tracking_domain": null,
              "signing_domain": null,
              "return_path_domain": null
            },
            "async": false,
            "ip_pool": "Main Pool"
        };
        var apiURL = "https://mandrillapp.com/api/1.0/messages/send.json";
        $http.post(apiURL, mailJSON).
          success(function(data, status, headers, config) {
            alert('successful email send.');
            $scope.form={};
            console.log('successful email send.');
            console.log('status: ' + status);
            console.log('data: ' + data);
            console.log('headers: ' + headers);
            console.log('config: ' + config);
          }).error(function(data, status, headers, config) {
            console.log('error sending email.');
            console.log('status: ' + status);
          });
      }
    })

提交回复
热议问题