Send Mailgun email with attachments Content-Type: multipart/form-data

I am trying to send an email with attachments. As per Mailgun docs here:
Content-Type: multipart/form-data
App is Angular ionic

Can you provide an example of doing? I have simple email sending working in the app through secure proxy.

User uploads files with ngFileUpload plugin: it returns a file in base64(["data:image/jpeg;base64,/9j/4AAQSkZJRgA.."]) or a Blob(]"blob:"])

Here are my settings, I changed Content-Type to Data:

Request Headers, I changed Content-Type too:

This code works for simple emails without attachments:

var requestData = {};
requestData = (function mapping6246($scope) {
var requestData = {};
requestData.params = Apperyio.EntityAPI('Mailgun_sending.request.query', undefined, true); = Apperyio.EntityAPI('Mailgun_sending.request.body', undefined, true); = from; = to; = subject; = body;

return requestData;



function(success) {
//$scope.alert("Email sent","Thanks for using Mailgun");

function(error) {

$scope.alert("Error sending email","Please check API settings");


function(notify) {


As usual, I find an answer before getting any response.

For anyone who wants to send free emails with attachments through Mailgun, here is quick guide.

First get a standard emails to work through proxy. has guides on that, or just import the plugin. Also, setup ngFileUpload, so you can upload files, make sure to specify ng-model property to store files in. For example mine is an array "$scope.tmpFormData.Attachments"

Next, change Request Content Type to Data.

Then, go to Request and delete the Content-Type header altogether, leave Authorization as is.

Then modify this code to your need:

//Creating a FromData object to be sent as request data
var formData = new FormData();
formData.append('to', '');
formData.append('from', "");
formData.append('subject', "Great Subject");
formData.append('text', "Great Text");
formData.append('attachment', $scope.tmpFormData.Attachments[0]);
formData.append('attachment', $scope.tmpFormData.Attachments[1]);

var requestData = {};
requestData = (function mapping9232($scope){
var requestData = {}; = Apperyio.EntityAPI('Mailgun_sending.request.body', undefined, true); = formData
requestData.headers = Apperyio.EntityAPI('Mailgun_sending.request.headers', undefined, true);
//requestData.headers['Content-Type'] = undefined;

return requestData;

// read more about using rest services:
function(success){ // success callback

function(error){ // callback to handle request error

function(notify){ // notify callback, can fire few times


If you are using a sandbox domain make sure to send to an authorized email address.
1 person has
this question