Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29758

How to send emails using mailgun in angularjs

$
0
0

I am using the following code to send emails in angularjs using the mailgun API.

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

But I am getting the following 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.

I had changed the following things in my code

  1. YOUR_DOMAIN_HERE with with-my-domain
  2. key-YOUR_API_KEY_HERE with with-my-api-key

Viewing all articles
Browse latest Browse all 29758

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>