使用 Nodemailer 从本地主机发送电子邮件 [英] Sending email from local host with Nodemailer

查看:92
本文介绍了使用 Nodemailer 从本地主机发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在本地服务器上发送邮件,但它似乎不适用于 Nodemailer 和 NodeJS.

I'd like to send mails on my local server but it seems not working with Nodemailer and NodeJS.

有没有办法从本地发送邮件?

Is there any solutions to send mails from local?

    var contact = {subject: 'test', message: "test message", email: 'visitor@gmail.com'};
    var to = "myemail@gmail.com";
    var transporter = nodemailer.createTransport();
    transporter.sendMail({
      from: contact.email,
      to: to,
      subject: contact.subject,
      text: contact.message
    });

推荐答案

  const transporter = nodemailer.createTransport({
    port: 25,
    host: 'localhost',
    tls: {
      rejectUnauthorized: false
    },
  });

  var message = {
    from: 'noreply@domain.com',
    to: 'whatever@otherdomain.com',
    subject: 'Confirm Email',
    text: 'Please confirm your email',
    html: '<p>Please confirm your email</p>'
  };

  transporter.sendMail(message, (error, info) => {
    if (error) {
        return console.log(error);
    }
    console.log('Message sent: %s', info.messageId);
  });

我目前正在通过 express.js 上的 Restful api 触发此操作

I'm current triggering this through an restful api on express.js

这应该可行,我用它来设置我在 digitalocean 上的后缀:https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-16-04

this should work, i used this to set up my postfix on digitalocean: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-16-04

这篇关于使用 Nodemailer 从本地主机发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆