Sending emails in Node.js? [closed]

2020-01-25 03:18发布

I recently started programming my first node.js. However, I discovered that I am unable to create a contact me form that sends straight to my email since I can't find any modules from node that is able to send emails.

Does anyone know of a node.js email library or an sample contact form script?

11条回答
该账号已被封号
2楼-- · 2020-01-25 03:37

Complete Code to send Email Using nodemailer Module

var mailer = require("nodemailer");

// Use Smtp Protocol to send Email
var smtpTransport = mailer.createTransport("SMTP",{
    service: "Gmail",
    auth: {
        user: "gmail_id@gmail.com",
        pass: "gmail_password"
    }
});

var mail = {
    from: "Yashwant Chavan <from@gmail.com>",
    to: "to@gmail.com",
    subject: "Send Email Using Node.js",
    text: "Node.js New world for me",
    html: "<b>Node.js New world for me</b>"
}

smtpTransport.sendMail(mail, function(error, response){
    if(error){
        console.log(error);
    }else{
        console.log("Message sent: " + response.message);
    }

    smtpTransport.close();
});
查看更多
在下西门庆
3楼-- · 2020-01-25 03:41

Nodemailer Module is the simplest way to send emails in node.js.

Try this sample example form: http://www.tutorialindustry.com/nodejs-mail-tutorial-using-nodemailer-module

Additional Info: http://www.nodemailer.com/

查看更多
兄弟一词,经得起流年.
4楼-- · 2020-01-25 03:42

campaign is a comprehensive solution for sending emails in Node, and it comes with a very simple API.

You instance it like this.

var client = require('campaign')({
  from: 'you@gmail.com'
});

To send emails, you can use Mandrill, which is free and awesome. Just set your API key, like this:

process.env.MANDRILL_APIKEY = '<your api key>';

(if you want to send emails using another provider, check the docs)

Then, when you want to send an email, you can do it like this:

client.sendString('<p>{{something}}</p>', {
  to: ['someone@gmail.com', 'someone.else@gmail.com'],
  subject: 'Some Subject',
  preview': 'The first line',
  something: 'this is what replaces that thing in the template'
}, done);

The GitHub repo has pretty extensive documentation.

查看更多
Emotional °昔
5楼-- · 2020-01-25 03:47

npm has a few packages, but none have reached 1.0 yet. Best picks from npm list mail:

email@0.2.2
mail@0.1.1
mailer@0.3.0
查看更多
欢心
6楼-- · 2020-01-25 03:47

You definitely want to use https://github.com/niftylettuce/node-email-templates since it supports nodemailer/postmarkapp and has beautiful async email template support built-in.

查看更多
Evening l夕情丶
7楼-- · 2020-01-25 03:47

node-email-templates is a much better option: https://github.com/niftylettuce/node-email-templates

it has support for windows as well

查看更多
登录 后发表回答