javascript - 从 AngularJS 网络应用程序发送电子邮件

标签 javascript angularjs email

在我的一个 AngularJS 网络应用程序中,我需要通过向相关人员发送电子邮件来确认密码。我怎样才能在 AngularJS 中实现这一点?我是 .NET 用户,我使用的是 Visual Studio 2013。

最佳答案

您还可以考虑使用第三方 SaaS,例如 Mandrill、SendGrid 或 MailGun。我曾使用 Mandrill 构建电子邮件功能。帐户可以免费设置,消息传递的计费阈值约为 12k/月。发送只是按照他们的 API 将 HTTP POST 发送到他们的 REST 接口(interface)的问题。下面的小例子:

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

关于javascript - 从 AngularJS 网络应用程序发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25759686/

相关文章:

javascript - 未捕获的类型错误 : Object 1 has no method 'indexOf'

javascript - 在 angularjs ng-change ="chk(query)"中,当输入单词后点击空格时调用函数

python - sendgrid python api取消订阅和管理列表标签

android - 如何在 Android 2.0.1 上获取电子邮件地址

javascript - 如何使谷歌地图不脱离世界界限?

javascript - 将数据传递给 vueJS 上的模态组件

javascript - 如何将 JS 键控对象转换为键控数组,同时跳过未定义?

angularjs - 如何在打开的模态组件中访问 `BsModalRef`?

javascript - ng-template 不在 jsFiddle 中显示 View

javascript - 错误 : Connection timeout at SMTPConnection. _formatError