Open mdakovac opened 3 years ago
getting this exact same error I have tried stripping all code down to the bare bones example as per docs (and you have above) and getting the same error.
Error: SyntaxError: Unexpected token M in JSON at position 0
Possibly connected to this issue. https://github.com/mailgun/mailgun-js/issues/134 see this comment https://github.com/mailgun/mailgun-js/issues/134#issuecomment-856135049 it has to do with the format of the domain.
@mdakovac could you try to use your real domain instead of a sandbox domain and report back if that has fixed it? then we can update the docs!
I fixed this error like this=>
In the domain, add your app's url, Do not add https , for example => sample.herokuapp.com and add another property url, here we have to add the mailgun api url. Refer to the example below
const auth = {
auth: {
api_key: "Your api key",
domain: "sample.herokuapp.com",
url: "https://api.mailgun.net/v3"
}
};
const nodemailerMailgun = nodemailer.createTransport(mg(auth));
I had the same error... The following structure solved it for me:
const mg = require("nodemailer-mailgun-transport")
module.exports = async function(req, res){
const mailgunAuth = {
auth: {
api_key: "",
domain: "mydomain.com",
url: "https://api.mailgun.net/v3"
}
}
const smtpTransport = nodemailer.createTransport(mg(mailgunAuth))
smtpTransport.sendMail({
from: 'Now Digital [email@email.com](mailto:email@email.com)',
to: '[emailclient@mail.com](mailto:emailclient@mail.com)',
subject: 'Teste de email!',
html: 'Email enviado com sucesso!',
}, (err, info) => {
if (err) {
console.log(Error: ${err});
res.json({'error': err})
}
else {
console.log(Response: ${info});
res.json('ok')
}
});
}
I get this error when trying to run the basic example:
versions:
"nodemailer": "^6.6.1", "nodemailer-mailgun-transport": "^2.1.3", node: 12
full error: