grails (11) vaadin (11) meteor (6) java (4) elasticsearch (3) apple (2) centos (1) cloudbees (1) google analytics (1) gradle (1) heroku (1) javafx (1) javascript (1) jdbc (1) jug (1) logback (1) logging (1) mac os (1) management (1) mongodb (1) mongolab (1) mysql (1) twitter (1) ubuntu (1)

Tuesday, July 30, 2013

Meteor: How to send email from client


  1. Make sure you have got email package in projectfolder/.meteor/packages file.
    email
    view raw packages hosted with ❤ by GitHub

  2. Create server side code in order to send email (Email.send can be called only on server side). That code you can call from client later on.
    Meteor.methods({
    sendEmail: function (userId, email) {
    if (this.userId == userId) {
    Email.send(email);
    }
    }
    });
    view raw server.js hosted with ❤ by GitHub

  3. Make a template that show a link that invokes client side JavaScript that sends the email.
    <template name='welcomePage'>
    <a id='send-email-button'>Send email</a>
    </template>

  4. Make the call from the client in order to send an email.
    Template.welcomePage.events({
    'click #send-email-button': function () {
    var email = {
    to: 'xyz@failtracker.com',
    from: 'abc@failtracker.com',
    replyTo: 'abct@failtracker.com',
    subject: "test email",
    text: "hello lover boy"
    };
    Meteor.call('sendEmail', this.userId, email);
    }
    });
    view raw client.js hosted with ❤ by GitHub




1 comment: