Meteor Js : How to do to send e-mail with a Mandrill account ?

First add the package :  meteor add wylio:mandrill

https://atmospherejs.com/wylio/mandrill

When the application startup you need do this :

Meteor.startup(function() {
    return Meteor.Mandrill.config({
        host: "smtp.mandrillapp.com",
        port: "587",
        username: "username@username.com.br",
        key: "keyMandrill" 
    });
});

You need create a method to call : ( server side )

Meteor.methods({
    sendEmail: function (from, subject, text) {
        check([from, subject, text], [String]);
        this.unblock();

        Meteor.Mandrill.send({
            to: "contact@contact.com",
            from: from,
            subject: subject,
            html: text
        });
    }
});

Example to use : ( client side )

email.html

<template name="email">
    <form>
        <div class="form-group">
            <input type="name" class="form-control" id="inputname" >
        </div>
        <div class="form-group">
            <input type="email" class="form-control" id="inputemail">
        </div>
        <div class="form-group">
            <input class="form-control" id="inputphone">
        </div>
        <textarea class="form-control" rows="3" id="inputMsg"></textarea>
        <button id="sendEmail" class="btn btn-default">Send</button>
    </form>               
</template>

email.js

Template.email.events({
    'click #sendEmail': function (e) {

        name = $('#inputname').val();
        email = $('#inputemail').val();
        phone = $('#inputphone').val();
        msg = $('#inputMsg').val();
        subject = "subject" + name;
        text = "Name" + name + "\n" +
        "Phone Number:" + phone + "\n" +
        "Msg:" + msg;

        Meteor.call('sendEmail',
            email,
            subject,
            text
        );
    }
});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s