2014-03-04 13:10:06 -05:00
|
|
|
logger = require('logger-sharelatex')
|
|
|
|
metrics = require('../../infrastructure/Metrics')
|
|
|
|
Settings = require('settings-sharelatex')
|
|
|
|
metrics = require("../../infrastructure/Metrics")
|
|
|
|
ses = require('node-ses')
|
|
|
|
|
2014-03-05 17:37:55 -05:00
|
|
|
if Settings.email? and Settings.email.fromAddress?
|
|
|
|
defaultFromAddress = ""
|
|
|
|
else
|
|
|
|
defaultFromAddress = Settings.email.fromAddress
|
2014-03-05 06:57:57 -05:00
|
|
|
|
2014-03-05 06:22:52 -05:00
|
|
|
if Settings.email?.ses? and Settings.email.ses?.key? and Settings.email.ses?.key != "" and Settings.email.ses?.secret? and Settings.email.ses?.secret != ""
|
|
|
|
client = ses.createClient({ key: Settings.email.ses.key, secret: Settings.email.ses.secret });
|
2014-03-04 13:10:06 -05:00
|
|
|
else
|
|
|
|
logger.warn "AWS SES credentials are not configured. No emails will be sent."
|
|
|
|
client =
|
|
|
|
sendemail: (options, callback = (err, data, res) ->) ->
|
|
|
|
logger.log options: options, "would send email if SES credentials enabled"
|
|
|
|
callback()
|
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
sendEmail : (options, callback = (error) ->)->
|
|
|
|
logger.log receiver:options.receiver, subject:options.subject, "sending email"
|
|
|
|
metrics.inc "email"
|
|
|
|
options =
|
|
|
|
to: options.to
|
2014-03-05 17:37:55 -05:00
|
|
|
from: defaultFromAddress
|
2014-03-04 13:10:06 -05:00
|
|
|
subject: options.subject
|
|
|
|
message: options.html
|
2014-03-05 07:06:28 -05:00
|
|
|
replyTo: options.replyTo || Settings.email.replyToAddress
|
2014-03-04 13:10:06 -05:00
|
|
|
client.sendemail options, (err, data, res)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, "error sending message"
|
|
|
|
else
|
|
|
|
logger.log "Message sent to #{options.to}"
|
|
|
|
callback(err)
|
|
|
|
|