Class: EcoRake::Utils::Mailer
- Inherits:
-
Object
- Object
- EcoRake::Utils::Mailer
- Defined in:
- lib/eco-rake/utils/mailer.rb
Overview
Mailer helper that uses aws-sdk-ses gem (Aws::SES::Client)
Several ENV vars should be configured for it to work (i.e. in the .env file):
MAILER_REGIONMAILER_KEY_IDMAILER_ACCESS_KEYMAILER_FROM
Instance Method Summary collapse
-
#configured? ⇒ Boolean
Whether or not the mailer is configured for usage.
-
#mail(to:, subject:, body:, from: nil, cc: nil, bcc: nil) ⇒ Object
Sends an email.
Instance Method Details
#configured? ⇒ Boolean
Returns whether or not the mailer is configured for usage.
43 44 45 |
# File 'lib/eco-rake/utils/mailer.rb', line 43 def configured? fetch_access_key_id && fetch_secret_access_key && fetch_region end |
#mail(to:, subject:, body:, from: nil, cc: nil, bcc: nil) ⇒ Object
Sends an email
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/eco-rake/utils/mailer.rb', line 15 def mail(to:, subject:, body:, from: nil, cc: nil, bcc: nil) unless configured? puts "Mailer: You are missing configuration parameters. Review your .env file" return false end ses.send_email( destination: fetch_to(to: to, cc: cc, bcc: bcc), source: fetch_from(from), message: { subject: { charset: "UTF-8", data: subject }, body: { # NOTEL: `html:` will let you send html instead # you can use both at once if you like text: { charset: "UTF-8", data: body } } } ).tap do |response| puts "Sent email to #{to} (MessageId: #{response.message_id})" end end |