Send email in Meteor.JS is as simple as ABC Meteor JS 08.06.2016


Send text email

The email package allows sending email from a Meteor app. To use it, add the package to your project by running in terminal

meteor add email check

Before we can actually send email in our application, we need to provide Meteor with access to an email provider. The server reads from the MAIL_URL environment variable to determine how to send mail and it variable should be of the form smtp://USERNAME:PASSWORD@HOST:PORT/.

There is Email.send method that only works on the server. Here is an example of how a client could use a server method call to send an email.

Let's define a method in server code that the client can call

import { Email } from 'meteor/email'

    sendEmail: function (to, from, subject, text) {
        check([to, from, subject, text], [String]);

        // Let other method calls from the same client start running,
        // without waiting for the email sending to complete.

            to: to,
            from: from,
            subject: subject,
            text: text

In client code call sendEmail method that asynchronously send an email'sendEmail',
    'Hello world!'

Send html template

You can render template with data on client by Blaze-toHTMLWithData and send to server. Also you can render render spacebars to html by meteor-spacebars-tohtml.

Also you can render template on server by meteorhacks:ssr.


meteor add meteorhacks:ssr

Create html template in private directory

# vim /project/private/mail.html

Hello <b>{{username}}</b>, <br>
You have subscribed to news!

In server code

SSR.compileTemplate('htmlEmail', Assets.getText('mail.html'));

let emailData = {
    username: "John Smith"

    to: "",
    from: "",
    subject: "Notification",
    html: SSR.render('htmlEmail', emailData)

Add attachment

You can add attachments property to Email.send with different options. Full description of options here.

Example (on sever)

    to: "",
    from: "",
    subject: "Notification",
    html: SSR.render('htmlEmail', emailData),
    attachments: [{filePath: '/home/www/temp/logo.png'}]

Test locally by MailDev

We can use MailDev to test mail sanding locally. MailDev is a simple way to test your projects' emails during development with an easy to use web interface that runs on your machine.

# install 
sudo npm install -g maildev

# run

You can see web interface at

Settings for Meteor.JS

# shell variable
export MAIL_URL='smtp://'

# in server code
Meteor.startup( function() {
    process.env.MAIL_URL = 'smtp://';

On server we can test mail send from meteor shell

# cd /project
# meteor shell

Email.send({to: "", from: "", subject: "Test",  text: 'Test'});