Created
June 15, 2016 09:34
-
-
Save olitomas/bad88a0d63f015ca89407a82edabc816 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sendEmail = function(settings) { | |
//attachmentName should be the full name. Example: reikningur.pdf | |
var s = { | |
from: settings.from, | |
replyTo: settings.replyTo, | |
to: settings.to, | |
subject: settings.subject, | |
body: settings.body, | |
attachment: settings.attachment, | |
attachmentName: settings.attachmentName, | |
attachmentType: settings.attachmentType | |
} | |
var allEmailsValid = true; | |
//to variable can be a string or an array of strings | |
var recipients = []; | |
if (s.to.constructor === Array) { | |
$.each(s.to, function(key, value) { | |
if (!_isValidEmail(value)) allEmailsValid = false; | |
recipients.push({ 'email': value }); | |
}); | |
} else { | |
recipients.push({ 'email': s.to }); | |
} | |
var m = new mandrill.Mandrill('hBA_uid-xHuZ68IaJs8LXQ'); | |
var params = { | |
message: { | |
from_email: s.from || '[email protected]', | |
headers: { | |
'Reply-To': s.replyTo || '[email protected]' | |
}, | |
to: recipients, | |
subject: s.subject, | |
html: s.body, | |
autotext: true, //turns html content to plaintext if mailclient does not support html | |
track_opens: true, | |
track_clicks: true | |
} | |
}; | |
if (s.attachment) { | |
params.message.attachments = [{ | |
type: s.attachmentType, | |
name: s.attachmentName, | |
content: s.attachment, | |
}]; | |
} | |
m.messages.send(params, function(rsp) { | |
return rsp; | |
}, function(error) { | |
console.log(error); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment