I want to send email without using email composer so I checked this tutorial (that don’t work) and this github repo for the integration of Ionic with Mailgun…
I’ve also checked this question on stackoverflow and I think that my code it’s the same but I’m not able to make it work on my Ionic App.
This is my code:
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {Http, Request, RequestMethod} from "@angular/http";
...
export class HomePage {
...
mailgunUrl: string;
mailgunApiKey: string;
...
constructor(
...
public http: HttpClient,
) {
this.http = http;
this.mailgunUrl = "mydomain";
this.mailgunApiKey = window.btoa("api:key...");
});
}
.....
send(recipient: string, subject: string, message: string) {
this.http.post("https://api.mailgun.net/v3/" + this.mailgunUrl + "/messages", "from=test@mail.it&to=" + recipient + "&subject=" + subject + "&text=" + message,
{
headers: { 'Authorization': 'Basic ' + this.mailgunApiKey, "Content-Type": "application/x-www-form-urlencoded" },
}).subscribe(success => {
console.log("SUCCESS -> " + JSON.stringify(success));
}, error => {
console.log("ERROR -> " + JSON.stringify(error));
});
}
...
On Postman it works perfectly, but not in my application, that gives me this error:
Where is the problem? I’m not able to understand it…I’m stuck from yesterday on this problem .