[英]How to send emails using mailgun in angularjs
我正在使用以下代碼使用 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.
我在我的代碼中更改了以下內容
您需要將以下內容添加到 index.html
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
此外,您可以將CORS 擴展程序添加到 Google Chrome。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.