如何通过带有angularjs的Mailgun发送电子邮件?

时间:2016-09-15 08:31:52

标签: angularjs mailgun

我正在尝试通过angularjs中的mailgun API发送,但它在这里不起作用是我的代码片段:

console.log('step1');

    var mailgunUrl = "DOMAIN_NAME";
    var mailgunApiKey = window.btoa("api:key-API_KEY")

    $scope.send = function () {
        console.log('in here');
        $http({
            "method": "POST",
            "url": "https://api.mailgun.net/v3/" + mailgunUrl + "/messages",
            "headers": {
                "Content-Type": "application/x-www-form-urlencoded",
                "Authorization": "Basic " + mailgunApiKey
            },
            data: "from=" + "test@example.com" + "&to=" + "TO_EMAIL_ADDRESS" + "&subject=" + "MailgunTest" + "&text=" + "EmailBody"
        }).then(function (success) {
            console.log("SUCCESS " + JSON.stringify(success));
        }, function (error) {
            console.log("ERROR " + JSON.stringify(error));
        });
    }

    console.log('step last');

它控制台“step1”和“step last”但不发送邮件。

你能帮帮我或建议我能做些什么。

谢谢

1 个答案:

答案 0 :(得分:0)

您是否添加了元标记:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">