''error: {message: "'from' parameter is missing"}' using Mailgun REST API from Angular 6 app
The from parameter is in the body. Why is this error happening?
export class EmailService {
constructor(private http: HttpClient) {}
sendMailgunMessage() {
const options = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
})
};
const body = {
username: 'api',
password: 'key-xxx',
from: '<[email protected]>',
to: '[email protected]',
subject: 'Subject text',
text: 'Body text',
multipart: true
};
return this.http.post('https://api.mailgun.net/v3/app.xxx.com/messages', body, options);
}
}
When I subscribe to the sendMailgunMessage function I get the error in the browser: HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "BAD REQUEST"...error : {message: "'from' parameter is missing"}
The xxx have been added to protect sensitive information. I also tried adding the API key to the URL, but that gave the same 'from' error.
Solution 1:[1]
- I'll recommend you using POSTMAN to test your api (use your function to create an instance and use 'GET' in POSTMAN to see the results), and see the response. You can also use 'POST' in POSTMAN to see if it works.
- Does it report other error, like other parameters are missing. If so, the reason can be you actually didn't pass any data when post.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PENG ZHU |
