codecombat/server/routes/contact.coffee

25 lines
956 B
CoffeeScript
Raw Normal View History

config = require '../../server_config'
2014-02-04 17:08:20 -05:00
log = require 'winston'
mail = require '../commons/mail'
2014-01-03 13:32:13 -05:00
module.exports.setup = (app) ->
2014-01-03 13:32:13 -05:00
app.post '/contact', (req, res) ->
2014-02-04 17:08:20 -05:00
log.info "Sending mail from #{req.body.email} saying #{req.body.message}"
if config.isProduction
2014-01-03 13:32:13 -05:00
options = createMailOptions req.body.email, req.body.message, req.user
mail.transport.sendMail options, (error, response) ->
2014-01-03 13:32:13 -05:00
if error
2014-02-04 17:08:20 -05:00
log.error "Error sending mail: #{error.message or error}"
2014-01-03 13:32:13 -05:00
else
2014-02-04 17:08:20 -05:00
log.info "Mail sent successfully. Response: #{response.message}"
2014-01-03 13:32:13 -05:00
return res.end()
createMailOptions = (sender, message, user) ->
# TODO: use email templates here
options =
from: config.mail.username
to: config.mail.username
replyTo: sender
subject: "[CodeCombat] Feedback - #{sender}"
text: "#{message}\n\nUsername: #{user.get('name') or 'Anonymous'}\nID: #{user._id}"
#html: message.replace '\n', '<br>\n'