2013-07-11 23:33:10 -04:00
class EmailWorker
include Sidekiq :: Worker
2013-07-12 06:12:48 +02:00
sidekiq_options queue : :emails , retry : 10 , backtrace : true
2013-07-11 23:33:10 -04:00
def perform ( args = { } )
2015-07-17 13:14:17 -07:00
return if ENV [ 'RACK_ENV' ] . nil? || ENV [ 'RACK_ENV' ] == 'development'
2015-01-07 15:24:15 -08:00
unsubscribe_token = Site . email_unsubscribe_token args [ 'to' ]
2015-03-11 12:19:40 -04:00
if args [ 'no_footer' ]
footer = ''
else
2015-06-29 13:54:49 -07:00
footer = " \n \n --- \n You are receiving this email because you have a Neocities site. If you would like to unsubscribe from Neocities emails, just visit this url: \n https://neocities.org/settings/unsubscribe_email?email= #{ Rack :: Utils . escape args [ 'to' ] } &token= #{ unsubscribe_token } "
2015-03-11 12:19:40 -04:00
end
2015-01-07 15:24:15 -08:00
2013-07-11 23:33:10 -04:00
Mail . deliver do
2014-09-12 19:09:58 -07:00
# TODO this is not doing UTF-8 properly.
from args [ 'from' ]
reply_to args [ 'reply_to' ]
to args [ 'to' ]
subject args [ 'subject' ]
2015-01-07 15:24:15 -08:00
body args [ 'body' ] + footer
2013-07-11 23:33:10 -04:00
end
end
end