Class: Mailthis::OutgoingEmail
- Inherits:
-
Object
- Object
- Mailthis::OutgoingEmail
- Defined in:
- lib/mailthis/outgoing_email.rb
Constant Summary collapse
- REQUIRED_FIELDS =
deliver a message using using Net::SMTP with TLS encryption it is recommended to use Mail (github.com/mikel/mail) messages to disable delivery, set βENV = βyesββ
[:from, :subject]
- ADDRESS_FIELDS =
[:to, :cc, :bcc]
Instance Attribute Summary collapse
-
#mailer ⇒ Object
readonly
Returns the value of attribute mailer.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
- #deliver ⇒ Object
- #deliver_dry_run {|self.message| ... } ⇒ Object
-
#initialize(mailer, message) ⇒ OutgoingEmail
constructor
A new instance of OutgoingEmail.
- #validate! ⇒ Object
Constructor Details
#initialize(mailer, message) ⇒ OutgoingEmail
Returns a new instance of OutgoingEmail.
18 19 20 21 22 23 24 |
# File 'lib/mailthis/outgoing_email.rb', line 18 def initialize(mailer, ) raise Mailthis::MessageError, "invalid message" if !() @mailer, @message = mailer, @message.from ||= @mailer.from @message.reply_to ||= @message.from end |
Instance Attribute Details
#mailer ⇒ Object (readonly)
Returns the value of attribute mailer.
16 17 18 |
# File 'lib/mailthis/outgoing_email.rb', line 16 def mailer @mailer end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
16 17 18 |
# File 'lib/mailthis/outgoing_email.rb', line 16 def @message end |
Instance Method Details
#deliver ⇒ Object
48 49 50 51 52 |
# File 'lib/mailthis/outgoing_email.rb', line 48 def deliver self.deliver_dry_run do |msg| deliver_smtp(msg) if ENV['MAILTHIS_DISABLE_SEND'].nil? end end |
#deliver_dry_run {|self.message| ... } ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/mailthis/outgoing_email.rb', line 38 def deliver_dry_run self.validate! @mailer.validate! yield(self.) if block_given? (self.) self. end |
#validate! ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mailthis/outgoing_email.rb', line 26 def validate! REQUIRED_FIELDS.each do |field| if !field_present?(@message, field) raise Mailthis::MessageError, "missing `#{field}` field" end end if !fields_present?(@message, ADDRESS_FIELDS) raise Mailthis::MessageError, "no #{ADDRESS_FIELDS.join('/')} specified" end end |