Skip to content

Send HTML email, email templating, send emails via SMTP [SERVER ONLY]

License

Notifications You must be signed in to change notification settings

satyavh/Meteor-Mailer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Meteor Mailer

Simply sends emails via built-in Email.send method, but with support of HTML-templates and SMTP.

If there is error with email sending, like connection to SMTP, - letter will be placed into queue and tried to send it 50 times after 60 seconds.

Initialization:

Meteor.mail = new Meteor.Mailer options

options {Object} - Object with next properties:

  • login {String} - [required] Your login on SMTP server, ex.: no-reply
  • host {String} - [required] Domain name or IP-address of SMTP server, ex.: smtp.example.com
  • connectionUrl {String} - [required] Connection (auth) URL with login, password and port, ex.: smtp://account:[email protected]:465
  • accountName {String} - Name of the account (usually shown next to or instead of email address). By default equals to login property, ex.: Some Service Name Support
  • intervalTime {Number} - How often try to send an email in seconds. By default 60 seconds, ex.: 600
  • retryTimes {Number} - How many times to retry to send email. By default 50, ex.: 10
  • saveHistory {Boolean} - Save sent emails. By default false, ex.: true
  • verbose {Boolean} - Show messages of sending/pending into server's console. By default false, ex.: true
  • template {String} - Path to html template, ex.: emailTemplates/signUp.html
  • if is not set, email will be sent within our default cute and sleek built-in template
  • template should be asset
  • read more about assets
Example:

For gmail hosted mail:

Meteor.mail = new Meteor.Mailer
  login: 'noreply-meteor'
  host: 'gmail.com'
  connectionUrl: "smtp://account:[email protected]:465"
  accountName: "My Project MailBot"
  verbose: true
  intervalTime: 120
  retryTimes: 10
  saveHistory: true
  template: 'emailTemplates/signUp.html'

For own hosted smtp server:

Meteor.mail = new Meteor.Mailer
  login: '[email protected]'
  host: 'smtp.example.com'
  connectionUrl: "smtp://[email protected]:[email protected]:587"
  accountName: "My Project MailBot"

Usage

send() method

Meteor.mail.send recipient, options, callback, sendAt, template
  • recipient {String} - Recipient email address
  • options {Object}
  • subject {String} - [required] Plain text or HTML
  • message {String} - [required] Plain text or HTML with placeholders
  • callback {Function} - With error, success and recipient parameters
  • sendAt {Date} - Date when email should be sent. By default current time
  • template {String} - Path to html template, ex.: emailTemplates/reset-password.html
  • if is not set, by default email will be sent within template passed via initialization options or our default template
  • template should be asset
  • read more about assets
Example:
Meteor.mail.send '[email protected]',
 message: "Some HTML or plain-text string (required)"
 subject: "Some HTML or plain-text string (required)"
 #Any optional keys, like
 appname: "Your application name"
 url: "http://localhost:3000"
 lang: 'en'
,
  (error, success, recipient) ->
    console.log("mail is not sent to #{recipient}") if error
    console.log("mail successfully sent to #{recipient}") if success
Template example:
<html lang="{{lang}}">
  <head>
    ...
    <title>{{Subject}}</title>
  </head>
  <body>
    <h3>{{{Subject}}}</h3>
    <p>{{{Message}}}</p>
    <footer>
      <a href="{{url}}">{{appname}}</a>
    </footer>
  </body>
</html>

About

Send HTML email, email templating, send emails via SMTP [SERVER ONLY]

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 93.4%
  • JavaScript 6.6%