 
 #TODO: html email (templates?)
 
-exports.signUpEmail = (user, token, callback) ->
+sendGridEmail = (mailOptions, callback) ->
   transport = nodemailer.createTransport 'SMTP',
     service: "SendGrid"
     auth:
       user: process.env.CU_SENDGRID_USER
       pass: process.env.CU_SENDGRID_PASS
 
+  # send mail with defined transport object
+  transport.sendMail mailOptions, (err, res) ->
+    transport.close()
+    if err?
+      callback err
+    else
+      callback null
+
+
+exports.signUpEmail = (user, token, callback) ->
   mailOptions =
     from: 'hello@scraperwiki.com'
     to: user.email[0]


    """

  # send mail with defined transport object
  transport.sendMail mailOptions, (err, res) ->
    transport.close()
    if err?
      callback err
    else
      callback null

exports.dataRequestConfirmation = (dataRequest, callback) ->
  transport = nodemailer.createTransport 'SMTP',
    service: "SendGrid"
    auth:
      user: process.env.CU_SENDGRID_USER
      pass: process.env.CU_SENDGRID_PASS

  mailOptions =
    from: process.env.CU_REQUEST_EMAIL
    to: dataRequest.email

    ScraperWiki
    """

  sendGridEmail mailOptions, callback

exports.dataRequestEmail = (dataRequest, callback) ->
  mailOptions =
    from: dataRequest.email
    to: process.env.CU_REQUEST_EMAIL
