-
Notifications
You must be signed in to change notification settings - Fork 2
/
mailer.coffee
43 lines (29 loc) · 1 KB
/
mailer.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
nodemailer = require("nodemailer")
Promise = require "promise"
readFile = Promise.denodeify(require('fs').readFile)
# create reusable transport method (opens pool of SMTP connections)
smtpTransport = nodemailer.createTransport("SMTP",
service: "Gmail"
auth:
user: ""
pass: ""
)
# send mail with defined transport object
sendEmail = (filename)->
html = readFile('./build/mq/'+filename+'.html', 'utf-8')
.then (html) ->
# console.log html
mailOptions =
from: "Fred Foo ✔ <[email protected]>" # sender address
to: "[email protected]" # list of receivers
subject: "Responsive Email" # Subject line
text: "Responsive Email" # plaintext body
html: html # html body
smtpTransport.sendMail mailOptions, (error, response) ->
if error
console.log error
else
console.log "Message sent: " + response.message
smtpTransport.close(); # shut down the connection pool, no more messages
return
module.exports = sendEmail