Class: Mmailer::MailHelper
- Inherits:
-
Object
- Object
- Mmailer::MailHelper
- Includes:
- ErrorHandling
- Defined in:
- lib/mmailer/mail_helper.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(args) ⇒ MailHelper
constructor
A new instance of MailHelper.
- #send_email(user) ⇒ Object
- #set_provider(provider) ⇒ Object
Methods included from ErrorHandling
Methods included from Client
Constructor Details
#initialize(args) ⇒ MailHelper
Returns a new instance of MailHelper.
6 7 8 9 10 11 |
# File 'lib/mmailer/mail_helper.rb', line 6 def initialize(args) set_provider args.fetch(:provider, :mandrill) @template=args[:template] @subject=args[:subject] @from=args[:from] end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
4 5 6 |
# File 'lib/mmailer/mail_helper.rb', line 4 def from @from end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
4 5 6 |
# File 'lib/mmailer/mail_helper.rb', line 4 def subject @subject end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
4 5 6 |
# File 'lib/mmailer/mail_helper.rb', line 4 def template @template end |
Instance Method Details
#send_email(user) ⇒ Object
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 |
# File 'lib/mmailer/mail_helper.rb', line 18 def send_email(user) mail = Mail.new mail.to = user.email mail.from = from mail.subject = subject #Defaulting to UTF-8, set your own if this is incorrect. mail.charset = 'UTF-8' mail.content_transfer_encoding = '8bit' compiled_source=ERB.new(File.read(Dir.pwd + "/" + Mmailer.configuration.template + ".md.erb")).result(binding) text_part = Mail::Part.new text_part.body=compiled_source html_part = Mail::Part.new html_part.content_type='text/html; charset=UTF-8' html_part.body=Kramdown::Document.new(compiled_source).to_html mail.text_part = text_part mail.html_part = html_part case ENV['MMAILER_ENV'] when "production" try { mail.deliver! } when "development" puts mail.to_s else mail.to_s end end |