我使用的是NodeJS,我想用Nodemailer配置我的电子邮件帐户。
我找到的所有 Nodemailer 示例都适用于Gmail ...
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'gmail.user@gmail.com',
pass: 'userpass'
}
});
如何提供其他服务?特别是我在ovh( SSL0.OVH.NET )中购买了一个电子邮件域名,我有兴趣配置此电子邮件帐户。
我试过了,但我找不到这样的方法......
谢谢!
答案 0 :(得分:4)
我为SMTP发送html邮件创建了一个模块Mail
exports.send = function(email, subject, htmlcontent, callback) {
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var configMail = require('../bin/config').mail;//my json configurations mail
var transporter = nodemailer.createTransport(smtpTransport({
host: configMail.host, //mail.example.com (your server smtp)
port: configMail.port, //2525 (specific port)
secureConnection: configMail.secureConnection, //true or false
auth: {
user: configMail.auth.user, //user@mydomain.com
pass: configMail.auth.pwd //password from specific user mail
}
}));
var mailOptions = {
from: configMail.email,
to: email,
subject: subject,
html: htmlcontent
};
transporter.sendMail(mailOptions, function(err, info){
transporter.close();
if(err) {
callback(err, info);
}
else {
callback(null, info);
}
});
}
用法:
var Mail = require('../utils/Mail'); //require this module
Mail.send('[EMAIL TO SEND]', '[TITLE]', '[YOUR HTML TEMPLATE MAIL]', function(err, info) {
if(err) {
//error
}
else {
//Email has been sent and you can see all information in var info
}
});
答案 1 :(得分:0)
在域中创建电子邮件ID(通常是通过c面板)时,检查该邮件地址的邮件配置,并查找SMTP详细信息,例如端口,用户名等。然后在nodemailer传输器中输入这些详细信息。例如,我的运输者详细信息为:
const transporter = nodemailer.createTransport({
host: "mail.schoolprogramming.tech",
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: "demo@schoolprogramming.tech",
pass: "**************"
}
});