import { Task, api, config} from "actionhero"; import nodemailer from 'nodemailer'; function emailValidator(p) { if (p.indexOf("@") < 0) { throw new Error("that is not an email address"); } } export class SendEmail extends Task { settings: SendEmailSettings; transporter: any; constructor() { super(); this.name = "sendEmail"; this.description = "send a email"; this.queue = "email"; this.frequency = 0; this.inputs = { subject: { required: true}, email: { required: true, validator: emailValidator }, message: {required: true} }; this.settings = config.shopifyMiddleware.emailTransporter; this.transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: this.settings.user, pass: this.settings.password } }); } async run(params) { var mailOptions = { from: this.settings.fromEmail, to: params.email, subject: params.subject, text: params.message }; this.transporter.sendMail(mailOptions, function(error, info){ if (error) { api.log(error, "error"); } else { api.log('Email sent: ' + info.response); } }); } } interface SendEmailSettings { service: string; user: string; password: string; fromEmail: string; }