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:48

Nodemailer is basically a module that gives you the ability to easily send emails when programming in Node.js. There are some great examples of how to use the Nodemailer module at http://www.nodemailer.com/. The full instructions about how to install and use the basic functionality of Nodemailer is included in this link.

I personally had trouble installing Nodemailer using npm, so I just downloaded the source. There are instructions for both the npm install and downloading the source.

This is a very simple module to use and I would recommend it to anyone wanting to send emails using Node.js. Good luck!

查看更多
放荡不羁爱自由
3楼-- · 2020-01-25 03:48

Check out emailjs

After wasting lots of time on trying to make nodemailer work with large attachments, found emailjs and happy ever since.

It supports sending files by using normal File objects, and not huge Buffers as nodemailer requires. Means that you can link it to, f.e., formidable to pass the attachments from an html form to the mailer. It also supports queueing..

All in all, no idea why nodejitsu ppl chose nodemailer to base their version on, emailjs is just much more advanced.

查看更多
▲ chillily
4楼-- · 2020-01-25 03:58

@JimBastard's accepted answer appears to be dated, I had a look and that mailer lib hasn't been touched in over 7 months, has several bugs listed, and is no longer registered in npm.

nodemailer certainly looks like the best option, however the url provided in other answers on this thread are all 404'ing.

nodemailer claims to support easy plugins into gmail, hotmail, etc. and also has really beautiful documentation.

查看更多
虎瘦雄心在
5楼-- · 2020-01-25 04:02

Mature, simple to use and has lots of features if simple isn't enought: Nodemailer: https://github.com/andris9/nodemailer (note correct url!)

查看更多
Viruses.
6楼-- · 2020-01-25 04:03

You could always use AlphaMail (disclosure: I'm one of the developers behind it).

Just install with NPM:

npm install alphamail

Sign up for a AlphaMail account. Get a token, and then you can start sending with the AlphaMail service.

var alphamail = require('alphamail');

var emailService = new alphamail.EmailService()
    .setServiceUrl('http://api.amail.io/v1/')
    .setApiToken('YOUR-ACCOUNT-API-TOKEN-HERE');

var person = {
    id: 1234,
    userName: "jdoe75",
    name: {
        first: "John",
        last: "Doe"
    },
    dateOfBirth: 1975
};

emailService.queue(new alphamail.EmailMessagePayload()
    .setProjectId(12345) // ID of your AlphaMail project (determines template, options, etc)
    .setSender(new alphamail.EmailContact("Sender Company Name", "from@example.com"))
    .setReceiver(new alphamail.EmailContact("John Doe", "to@example.org"))
    .setBodyObject(person) // Any serializable object
);

And in the AlphaMail GUI (Dashboard) you'll be able to edit the template with the data you sent:

<html>
    <body>
        <b>Name:</b> <# payload.name.last " " payload.name.first #><br>
        <b>Date of Birth:</b> <# payload.dateOfBirth #><br>

        <# if (payload.id != null) { #>
            <a href="http://company.com/sign-up">Sign Up Free!</a>
        <# } else { #>
            <a href="http://company.com/login?username=<# urlencode(payload.userName) #>">Sign In</a>
        <# } #>
    </body>
</html>

The templates are written in Comlang, it's a simple template language specifically designed for emails.

查看更多
登录 后发表回答