{"size": 742, "ext": "js", "max_stars_repo_path": "imports/lib/EmailWorker/utilities/sendInviation.js", "max_stars_repo_name": "Enterjoy/writernote", "max_stars_repo_stars_event_min_datetime": "2016-10-13T08:33:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-09T18:13:14.000Z", "max_issues_repo_path": "imports/lib/EmailWorker/utilities/sendInviation.js", "max_issues_repo_name": "Enterjoy/writernote", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "imports/lib/EmailWorker/utilities/sendInviation.js", "max_forks_repo_name": "Enterjoy/writernote", "max_forks_repo_forks_event_min_datetime": "2016-10-15T12:40:55.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-09T18:13:15.000Z"}
{"max_stars_count": 5, "max_issues_count": null, "max_forks_count": 3, "avg_line_length": 19.5263157895, "max_line_length": 57, "alphanum_fraction": 0.5849056604}
import DOM from 'react-dom/server';
import React from 'react';

import { Invitation } from '../templates/Invitation.jsx';

import mailgun from 'mailgun-js';

export function sendInviation(data) {
  check(data, {
    to: String,
    user: String,
    book: String,
    link: String,
  });

  const {
    to,
  } = data;

  Meteor.defer(function() {
    const mg = mailgun({
      apiKey: Meteor.settings.private.mailgun.key,
      domain: Meteor.settings.private.mailgun.domain,
    });

    mg.messages().send({
      from: 'support@writernote.com',
      to,
      subject: 'Writer Note: Invite to edit',
      html: DOM.renderToString(<Invitation {...data} />),
    }, (err) => {
      if (err) {
        throw err;
      }
    });
  });
}
