Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Mailing Service
express = require 'express'
skipper = require 'skipper'
nodemailer = require 'nodemailer'
app = express()
verifyToken = (req, res, next) ->
token = req.body.token || req.query.token || req.headers['x-access-token']
if token is process.env.TOKEN
next()
else
res.status(403).send
success: false
message: if token then 'No token provided.' else 'Failed to authenticate token.'
transporter = nodemailer.createTransport
pool: true
host: 'smtp.gmail.com'
port: 465
secure: true
auth:
user: process.env.USER
pass: process.env.PASS
app.use skipper()
app.use verifyToken
app.post '*', (req, res) ->
req.file('attachment').upload (err, files) ->
return res.send 500, err if err
data = req.body
data.attachments =
for file in files
filename: file.filename
path: file.fd
transporter.sendMail data, (error, info) ->
if error
console.log error
return
console.log 'Message sent: ' + info.response
res.send data
module.exports = app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment