Class | Mack::Notifier::Adapters::Tmail |
In: |
lib/mack-notifier/adapters/tmail.rb
|
Parent: | Mack::Notifier::Adapters::Base |
Converts a Mack::Notifier object into a TMail object.
Converts the Mack::Notifier object to a TMail object.
# File lib/mack-notifier/adapters/tmail.rb, line 23 23: def convert 24: @tmail = TMail::Mail.new 25: @tmail.to = mack_notifier.to 26: @tmail.cc = mack_notifier.cc 27: @tmail.bcc = mack_notifier.bcc 28: @tmail.reply_to = mack_notifier.reply_to 29: @tmail.from = mack_notifier.from 30: @tmail.subject = mack_notifier.subject 31: @tmail.date = mack_notifier.date_sent 32: @tmail.mime_version = mack_notifier.mime_version 33: 34: # set text and html bodies 35: main_body = TMail::Mail.new 36: unless mack_notifier.body(:plain).blank? 37: text = TMail::Mail.new 38: text.content_type = "text/plain" 39: text.body = mack_notifier.body(:plain) 40: main_body.parts << text 41: end 42: unless mack_notifier.body(:html).blank? 43: html = TMail::Mail.new 44: html.content_type = "text/html" 45: html.body = mack_notifier.body(:html) 46: main_body.parts << html 47: end 48: unless main_body.parts.empty? 49: main_body.content_type = "multipart/alternative" 50: @tmail.parts << main_body 51: end 52: 53: # set attachments, if any. 54: mack_notifier.attachments.each do |at| 55: attachment = TMail::Mail.new 56: attachment.body = Base64.encode64(at.body) 57: attachment.transfer_encoding = "Base64" 58: attachment.content_type = "application/octet-stream" 59: attachment['Content-Disposition'] = "attachment; filename=#{at.file_name}" 60: @tmail.parts << attachment 61: end 62: 63: @tmail.content_type = mack_notifier.content_type 64: end
Returns the ready to be delivered encoded String
# File lib/mack-notifier/adapters/tmail.rb, line 18 18: def deliverable 19: transformed.encoded 20: end
Returns the underlying TMail object. Raises Mack::Errors::UnconvertedNotifier if the convert method hasn‘t been called first.
# File lib/mack-notifier/adapters/tmail.rb, line 12 12: def transformed 13: raise Mack::Errors::UnconvertedNotifier.new if @tmail.nil? 14: @tmail 15: end