Reputation: 61
I've started putting together a simple mailer with node.js and the nodemailer module. The mailer is working and I'm able to connect via SMTP transport on my server, but I'm having trouble pushing the attachment to the message.
I originally setup with well known service module with iCloud and the file was parsing just file, but when I switched to SMTP, I can't seem to get around it which is odd.
// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP",{
host: 'mail.server.com',
port: 25,
secureConnection: false,
auth: {
user: '[email protected]',
pass: 'pass'
},
tls:{
ciphers:'SSLv3'
}
});
console.log('SMTP Configured');
var mailOptions;
// Message object
app.get('/send', function (req, res) {
mailOptions = {
from: '[email protected]',
to: req.query.toAddress,
subject: req.query.messageSub,
html: '<img src="cid:img@server" alt="" />,
attachments: [
{
fileName: 'gif.gif',
path: req.query.imageURL,
cid: 'img@server'
}
]
};
console.log('Sending Mail..');
transport.sendMail(mailOptions, function (error) {
if (error) {
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
transport.close(); // close the connection pool
res.redirect('/');
return;
});
});
I'm using the get method to get the fields from a form, logging it console, I see everything is parsed to the app.js file, but the attachment is either missing or contains an error , which makes me believe there's something wrong with the path, everything else gets sent ok.
The path I'm parsing (I tried manually putting it instead of req.query.imageURL as well) looks like this, but I tried other combinations:
'./public/including/christmas-gif.gif'
If I use a URL with http://... , I'm able to parse the file as well. I'll be glad for any tips.
Upvotes: 3
Views: 1371
Reputation: 61
I have resolved this by setting up some extra options for the transport and updating the nodemailer from 0.7 to 1.0 with smtp-transport module like so...
// Create a SMTP transport object
var transport = nodemailer.createTransport(smtpTransport({
host: 'mail.server.com',
port: '25',
secure: false,
ignoreTLS: true,
auth: {
user: '[email protected]',
pass: 'pass'
},
tls:{
ciphers:'SSLv3',
rejectUnauthorized: true
},
authMethod: 'PLAIN',
debug: true
}));
Upvotes: 2