如何使用JavaScript使用Mandrill发送电子邮件?

拉尔夫·大卫·阿伯纳西

我已遵循指南,了解如何通过Mandrill使用JavaScript发送电子邮件,但在我的控制台中收到此错误:Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://mandrillapp.com/api/1.0/messages/send.json. This can be fixed by moving the resource to the same domain or enabling CORS.

这是我的代码:

$('#submitEmail').click(function() {
  $.ajax({
    type: "POST",
    url: "https://mandrillapp.com/api/1.0/messages/send.json",
    data: {
      'key': 'my_api_key',
      'message': {
        'from_email': '[email protected]',
        'to': [{
          'email': '[email protected]',
          'name': 'RECIPIENT NAME (OPTIONAL)',
          'type': 'to'
        }],
        'autotext': 'true',
        'subject': 'test',
        'html': 'test'
      }
    }
  }).done(function(response) {
    console.log(response);
  });
});

我究竟做错了什么?

AstroCB

与其发出POST请求,不如在您标签中包含Mandrill API<script><head>

<script type="text/javascript" src="path_to_locally_stored_copy_of_mandrill_API"></script>

然后,您可以在JS文件中访问它:

var m = new mandrill.Mandrill('your_api_key'); // This will be public

function sendTheMail(){
    m.messages.send({
        "message": {
            "from_email": "your_email_address",
            "from_name": "your_name",
            "to":[{"email": "someone's_email_address", "name": "someone's_name"}], // Array of recipients
            "subject": "optional_subject_line",
            "text": "Text to be sent in the body" // Alternatively, use the "html" key to send HTML emails rather than plaintext
        }
    });
}

但是,请注意,这会将您的API公开,因为可以使用开发工具从客户端进行访问。这可能使您容易遭受网上诱骗漏洞的攻击,并且有人可能会滥用您的密钥。

我也想看看在全山魈文档send

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用PHP使用Mandrill发送电子邮件

来自分类Dev

使用Mandrill(php)发送电子邮件时出错

来自分类Dev

使用Mandrill中的模板发送电子邮件

来自分类Dev

使用Mandrill(php)发送电子邮件时出错

来自分类Dev

如何使用Mandrill API向多个收件人发送电子邮件?

来自分类Dev

如何使用 Parse 和 Mandrill 发送电子邮件通知?

来自分类Dev

通过Mandrill发送电子邮件

来自分类Dev

如何使用Tibco邮件活动发送电子邮件

来自分类Dev

使用 SendGrid 发送电子邮件的 Javascript Azure 函数

来自分类Dev

使用Google Apps和Mandrill / Sendgrid发送电子邮件

来自分类Dev

当我尝试在Android中使用Mandrill SMTP发送电子邮件时出错

来自分类Dev

无法使用Mandrill发送电子邮件的问题->部署到Heroku

来自分类Dev

使用sendmail发送电子邮件

来自分类Dev

使用php发送电子邮件

来自分类Dev

使用mail()发送电子邮件

来自分类Dev

使用nodemailer发送电子邮件

来自分类Dev

使用VBScript发送电子邮件

来自分类Dev

使用nodemailer发送电子邮件

来自分类Dev

使用Gradle发送电子邮件

来自分类Dev

使用Javax发送电子邮件?

来自分类Dev

使用SSL发送电子邮件

来自分类Dev

使用Phonegap发送电子邮件

来自分类Dev

使用SwiftUI发送电子邮件

来自分类Dev

使用sendmail发送电子邮件

来自分类Dev

使用Telnet发送电子邮件

来自分类Dev

使用SSL发送电子邮件

来自分类Dev

使用Gradle发送电子邮件

来自分类Dev

使用 netcat 发送电子邮件

来自分类Dev

使用 Lua 发送电子邮件