Utiliser Gmail
var nodemailer = require('nodemailer');
// Create the transporter with the required configuration for Gmail
// change the user and pass !
var transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true, // use SSL
auth: {
user: '[email protected]',
pass: 'myPassword'
}
});
// setup e-mail data
var mailOptions = {
from: '"Our Code World " <[email protected]>', // sender address (who sends)
to: '[email protected], [email protected]', // list of receivers (who receives)
subject: 'Hello', // Subject line
text: 'Hello world ', // plaintext body
html: '<b>Hello world </b><br> This is the first email sent with Nodemailer in Node.js' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
utilisant Hotmail
var nodemailer = require('nodemailer');
// Create the transporter with the required configuration for Outlook
// change the user and pass !
var transporter = nodemailer.createTransport({
host: "smtp-mail.outlook.com", // hostname
secureConnection: false, // TLS requires secureConnection to be false
port: 587, // port for secure SMTP
tls: {
ciphers:'SSLv3'
},
auth: {
user: '[email protected]',
pass: 'myPassword'
}
});
// setup e-mail data, even with unicode symbols
var mailOptions = {
from: '"Our Code World " <[email protected]>', // sender address (who sends)
to: '[email protected], [email protected]', // list of receivers (who receives)
subject: 'Hello ', // Subject line
text: 'Hello world ', // plaintext body
html: '<b>Hello world </b><br> This is the first email sent with Nodemailer in Node.js' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
Par ailleurs, si votre compte est hotmail au lieu de perspectives, vous pouvez utiliser la Buil en service hotmail en utilisant le transport suivant:
var transport = nodemailer.createTransport("SMTP", {
service: "hotmail",
auth: {
user: "[email protected]",
pass: "password"
}
});
En utilisant Zoho
var nodemailer = require('nodemailer');
// Create the transporter with the required configuration for Gmail
// change the user and pass !
var transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port: 465,
secure: true, // use SSL
auth: {
user: '[email protected]',
pass: 'myPassword'
}
});
// setup e-mail data, even with unicode symbols
var mailOptions = {
from: '"Our Code World " <[email protected]>', // sender address (who sends)
to: '[email protected], [email protected]', // list of receivers (who receives)
subject: 'Hello ', // Subject line
text: 'Hello world ', // plaintext body
html: '<b>Hello world </b><br> This is the first email sent with Nodemailer in Node.js' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
Où est la propriété 'method' dans le code fourni? – ppovoski