I created the following function with NodeMailer which seems to be despatching emails without problems ("Message sent" notification in console and email received) except there are no attachments with any emails sent!
Tried it with a bunch of email addresses (gmail, google apps, hotmail) but all are doing the same thing. Please help!
var sendWithAttachment = function(userMail, subject, html, attachment_path, cb){
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "labs@domain.com",
pass: "password"
}
});
var mailOptions = {
from: "Labs <labs@domain.com>",
to: userMail,
subject: subject || "[blank]"
html: html || "[none]"
generateTextFromHTML: true,
attachments: [
{ // filename and content type is derived from path
path: attachment_path
},
{ // utf-8 string as an attachment
filename: 'check.txt',
content: 'checking that some attachments work...'
},
],
};
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
cb(error, null);
}else{
console.log("Message sent: " + response.message);
cb(null, response);
}
smtpTransport.close();
});
};