Mailgun is giving me a HTTP code of 400 which according to their docs means
Bad Request - Often missing a required parameter https://documentation.mailgun.com/en/latest/api-intro.html#errors
I have the mail sending function in a firebase cloud function, this is the cloud function
app.post('/sendMail', (req, res) => { const data = { from: 'Excited User <me@samples.mailgun.org>', to: 'email, apikey', subject: 'Hello', text: 'Testing some Mailgun awesomness!' }; mailgun.messages().send(data, function (error, body) { if(error){ console.log(error); res.send(error) } console.log(body); res.send('sent email!') }); }); exports.app = functions.https.onRequest(app);
I call this function inside my app this the code inside the app:
sendEmail(){ let url = `URL to my cloud function`; let params: URLSearchParams = new URLSearchParams(); let data = { from: 'Excited User <me@samples.mailgun.org>', to: 'myEmail , apiKey', subject: 'Hello', text: 'Testing some Mailgun awesomness!' }; return this.http.post(url,data) .toPromise() .then(res=>{ console.log(`Res:`,res); }) .catch(err => { console.log('Error',err); }) }
I have followed the firebase API https://documentation.mailgun.com/en/latest/quickstart-sending.html#send-via-api i do not know what parameters are missing as i just copied and pasted their sample code
I changed this
const data = { from: 'Excited User <me@samples.mailgun.org>', to: 'email, apikey', subject: 'Hello', text: 'Testing some Mailgun awesomness!' };
To:
const data = { from: 'me@samples.mailgun.org', to: 'email', subject: 'Hello', text: 'Testing some Mailgun awesomness!' };
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.