Class: Talktome::Strategy::Email
- Inherits:
-
Talktome::Strategy
- Object
- Talktome::Strategy
- Talktome::Strategy::Email
- Defined in:
- lib/talktome/strategy/email.rb
Instance Method Summary collapse
-
#initialize(options = {}, &defaulter) ⇒ Email
constructor
A new instance of Email.
- #send_message(message, user) {|mail| ... } ⇒ Object
Constructor Details
#initialize(options = {}, &defaulter) ⇒ Email
Returns a new instance of Email.
6 7 8 9 |
# File 'lib/talktome/strategy/email.rb', line 6 def initialize( = {}, &defaulter) @options = @defaulter = defaulter end |
Instance Method Details
#send_message(message, user) {|mail| ... } ⇒ Object
11 12 13 14 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 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/talktome/strategy/email.rb', line 11 def (, user) # Take a base email, with all info coming from the environment (if set) mail = base_email # Override environment defaults with template behavior, for flexibility [ :to, :reply_to, :in_reply_to, :attachments, :subject ].each do |which| if arg = .[which.to_s] mail.send(:"#{which}=", arg) end end # If the user is actually known from source code behavior, override the # `mail.to` to send the email to that particular person. mail.to = user[:email] if user.has_key?(:email) case .extension when 'md', 'html', 'htm' mail.text_part do content_type 'text/plain; charset=UTF-8' body .to_text end mail.html_part do content_type 'text/html; charset=UTF-8' body .to_html end when 'text' mail.body .to_text else raise "Unsupported extension `#{.extension}`" end yield(mail) if block_given? mail.deliver! end |