Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to send mail via Mailgun over api or smtp

Tags:

mailgun

I have setup a new account and not verified my domain. I would like to test and confirm mail-send before proceeding with verification and adding payment information.

I have tried curl using the sandbox method and api key (including smtp). I have also tried to use my domain using the top account mail-address as recipient. But each time the send command (both curl and smtp) I get "Mailgun Magnificent API" response - but no mail is delivered. So far the Mailgun API does not look so Magnificent... I have gone through the documentation multiple times and cannot find what I might be doing wrong..

Any help is much appreciated.

like image 748
user1055761 Avatar asked Jul 22 '17 14:07

user1055761


1 Answers

The mailgun guide shows you to use https://api.mailgun.net/v3/YOUR_DOMAIN as YOUR_DOMAIN_NAME as in the snippet below and this was the problem.

If you're using mailgun-js, you simply need to have YOUR_DOMAIN as YOUR_DOMAIN_NAME.

No need for the https://api.mailgun.net/v3 part

const API_KEY = 'YOUR_API_KEY';
const DOMAIN = 'YOUR_DOMAIN_NAME';
const mailgun = require('mailgun-js')({apiKey: API_KEY, domain: DOMAIN});

const data = {
  from: 'Excited User <[email protected]>',
  to: '[email protected], [email protected]',
  subject: 'Hello',
  text: 'Testing some Mailgun awesomeness!'
};

mailgun.messages().send(data, (error, body) => {
  console.log(body);
});
like image 148
aifodu Avatar answered Sep 28 '22 18:09

aifodu