(side note: I also posted this on stackoverflow)
I am trying to send a log file through mailgun from my Ionic 2 app on an Android device. The file is a plain-text csv file, that I successfully created earlier in the app with File.writeFile command:
File.writeFile(cordova.file.externalRootDirectory, "data.csv", "...")
I am able to send emails through Mailgun, so I know that the basic configuration is set up correctly. Emails get sent (including subject and text) but without the attachment. My latest approach was:
let formData = new FormData();
formData.append("from", "someone@gmail.com");
formData.append("to", "someone@gmail.com");
formData.append("subject", "test");
formData.append("text", "plain email works");
formData.append("attachment", cordova.file.externalRootDirectory + 'data.csv');
this.http.post("https://api:key-MYAPIKEY@api.mailgun.net/v3/MYDOMAIN/messages", formData)
.map(result => result.json())
.do(result => console.log("RESULT", JSON.stringify(result)))
.subscribe(result => {
console.log("SENT!");
}, error => {
console.log(error);
});
I also tried to explicitly state the Content-Type:
let headers = new Headers(
{
"Content-Type": "multipart/form-data",
"Authorization": "Basic " + MYAPIKEY //(base64 encoded)
}
);
let options = new RequestOptions({headers: headers});
this.http.post("https://api.mailgun.net/v3/"+this.mailgunUrl+"/messages", formData, options)
Instead of passing just path and filename I also tried to use File.getFile but without much success. Would be great if someone could help. Thanks a lot!