Class: Courrier::Email
- Inherits:
-
Object
- Object
- Courrier::Email
- Defined in:
- lib/courrier/email.rb,
lib/courrier/email/result.rb,
lib/courrier/email/address.rb,
lib/courrier/email/layouts.rb,
lib/courrier/email/options.rb,
lib/courrier/email/request.rb,
lib/courrier/email/provider.rb,
lib/courrier/email/transformer.rb,
lib/courrier/email/providers/base.rb,
lib/courrier/email/providers/inbox.rb,
lib/courrier/email/providers/loops.rb,
lib/courrier/email/providers/logger.rb,
lib/courrier/email/providers/resend.rb,
lib/courrier/email/providers/mailgun.rb,
lib/courrier/email/providers/mailjet.rb,
lib/courrier/email/providers/mailpace.rb,
lib/courrier/email/providers/postmark.rb,
lib/courrier/email/providers/sendgrid.rb,
lib/courrier/email/providers/userlist.rb,
lib/courrier/email/providers/sparkpost.rb
Defined Under Namespace
Modules: Address, Providers Classes: Layouts, Options, Provider, Request, Result, Transformer
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#default_url_options ⇒ Object
Returns the value of attribute default_url_options.
-
#options ⇒ Object
Returns the value of attribute options.
-
#provider ⇒ Object
Returns the value of attribute provider.
Class Method Summary collapse
- .configure(**options) ⇒ Object (also: set)
- .deliver(options = {}) ⇒ Object
- .deliver_now ⇒ Object
- .inherited(subclass) ⇒ Object
- .layout(options = {}) ⇒ Object
Instance Method Summary collapse
- #deliver ⇒ Object (also: #deliver_now)
-
#initialize(options = {}) ⇒ Email
constructor
A new instance of Email.
Constructor Details
#initialize(options = {}) ⇒ Email
Returns a new instance of Email.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/courrier/email.rb', line 50 def initialize( = {}) @provider = [:provider] || ENV["COURRIER_PROVIDER"] || self.class.provider || Courrier.configuration&.provider @api_key = [:api_key] || ENV["COURRIER_API_KEY"] || self.class.api_key || Courrier.configuration&.api_key @default_url_options = self.class..merge([:default_url_options] || {}) @context_options = .except(:provider, :api_key, :from, :to, :reply_to, :cc, :bcc, :subject, :text, :html) @options = Email::Options.new( .merge( from: [:from] || self.class.from || Courrier.configuration&.from, reply_to: [:reply_to] || self.class.reply_to || Courrier.configuration&.reply_to, cc: [:cc] || self.class.cc || Courrier.configuration&.cc, bcc: [:bcc] || self.class.bcc || Courrier.configuration&.bcc, subject: subject, text: text, html: html, auto_generate_text: Courrier.configuration&.auto_generate_text, layouts: Courrier::Email::Layouts.new(self).build ) ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object (private)
94 |
# File 'lib/courrier/email.rb', line 94 def method_missing(name, *) = @context_options[name] |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/courrier/email.rb', line 10 def api_key @api_key end |
#default_url_options ⇒ Object
Returns the value of attribute default_url_options.
10 11 12 |
# File 'lib/courrier/email.rb', line 10 def @default_url_options end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/courrier/email.rb', line 10 def @options end |
#provider ⇒ Object
Returns the value of attribute provider.
10 11 12 |
# File 'lib/courrier/email.rb', line 10 def provider @provider end |
Class Method Details
.configure(**options) ⇒ Object Also known as: set
30 31 32 |
# File 'lib/courrier/email.rb', line 30 def configure(**) .each { |key, value| send("#{key}=", value) if respond_to?("#{key}=") } end |
.deliver(options = {}) ⇒ Object
25 26 27 |
# File 'lib/courrier/email.rb', line 25 def deliver( = {}) new().deliver_now end |
.deliver_now ⇒ Object
28 29 30 |
# File 'lib/courrier/email.rb', line 28 def deliver( = {}) new().deliver_now end |
.inherited(subclass) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/courrier/email.rb', line 39 def inherited(subclass) super # If you read this and know how to move this Rails-specific logic somewhere # else, e.g. `lib/courrier/railtie.rb`, open a PR ❤️ if defined?(Rails) && Rails.application subclass.include Rails.application.routes.url_helpers end end |
.layout(options = {}) ⇒ Object
35 36 37 |
# File 'lib/courrier/email.rb', line 35 def layout( = {}) self.layouts = end |
Instance Method Details
#deliver ⇒ Object Also known as: deliver_now
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/courrier/email.rb', line 71 def deliver if delivery_disabled? Courrier.configuration&.logger&.info "[Courrier] Email delivery skipped: delivery is disabled via environment variable" return nil end Provider.new( provider: @provider, api_key: @api_key, options: @options, provider_options: Courrier.configuration&.providers&.[](@provider.to_s.downcase.to_sym), context_options: @context_options ).deliver end |