thanks in advance for your responses. I have written some code that uses nodemailer 0.7.1.It sends the email and attaches a pdf to the email. However,the .pdf attachment either corrupts itself when encoding or truncates or something. The reason I say this is the file before attachment(i.e. the one I have locally) is 512kb and the attachment in the email is only 1kb.
This is the code that uses nodemailer:
var nodemailer = require("nodemailer");
var util = require("./util");
var env = require('./environment');
var smtpTransport = nodemailer.createTransport("SMTP",{
service: env.service,
auth: {
user: env.user,
pass: env.password
}
});
exports.sendAttachment = function(info, callback, debug) {
util.validatInput(info, ["body"] , function(err, info){
if(err){
util.errPrint(err, "serverUtil/nodemailer.sendAttachment", 1, function(message){callback(err);});
}else {
var mailOptions={
from : "[email protected]",
to : "[email protected]",
subject : "Application from " + info.userEmail,
text : info.body,
attachments: [
{
fileName: 'file.pdf', //This needs to be the link to the form, or the actual form
filePath: 'file.pdf',
contentType: "application/pdf"
}
]
}
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
callback(err);
}
else{
console.log("Message sent: " + response.message);
callback({msg: "form sent"});
}
});
}
})
}
I am using google chrome as a browser but have tried with other browsers to no avail. Obviously though browsers shouldn't have anything to do with this as the data of the pdf itself is the issue here.
I put the file in the same directory to avoid problems and even did './'before the file for current directory. I also changed 'filepath' to 'path' and then it didn't send any attachment at all.
I think the problem is in the 'attachments' array. Maybe the fields aren't right or I need to add some more information.
If anyone can tell me if I need to stream or something rather than what I am doing and if so how to stream the file that would be great!