【发布时间】:2016-09-05 23:29:12
【问题描述】:
我正在使用以下代码使用 mailgun API 在 angularjs 中发送电子邮件。
.controller("MailgunController", function($scope, $http) {
var mailgunUrl = "YOUR_DOMAIN_HERE";
var mailgunApiKey = window.btoa("api:key-YOUR_API_KEY_HERE")
$scope.send = function() {
$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=" + "soeone@gmail.com" + "&subject=" + "MailgunTest" + "&text=" + "EmailBody"
}).then(function(success) {
console.log("SUCCESS " + JSON.stringify(success));
}, function(error) {
console.log("ERROR " + JSON.stringify(error));
});
}
})
但我收到以下错误!
XMLHttpRequest cannot load https://api.mailgun.net/v3/MY-URL/messages. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.
我在代码中更改了以下内容
- YOUR_DOMAIN_HERE with with-my-domain
- key-YOUR_API_KEY_HERE with with-my-api-key
【问题讨论】:
标签: javascript angularjs rest email mailgun