Sunday, May 5, 2013

Rails Action Mailer simple settings

1) we can set perform_deliveries as false . this is may be used in development mode. As sometimes we want to keep development time less . like when sending an email it might take some seconds and in development mode we actually never required to send emails to our friends that is why this option is useful.
2) we can override cc and bcc and reply-to and charset options in our mailer instance method. the default charset is UTF-8 e.g

def post_notification(recipients, post)
       @recipients = recipients
       @from = post.author.email_address_with_name
       @headers["bcc"] = SYSTEM_ADMINISTRATOR_EMAIL
       @headers["reply-to"] = "notifications@example.com"
       @subject = "[#{post.account.name} #{post.title}]"
       @body["post"] = post
       @charset = "iso-8859-1"

end 


  
Rails 4 mailer changes 

 in rails 4 for each object for sending an email we can change an SMTP settings. means we can do a dynamic smtp settings.by overriding the following method

def my_mailer(receiverobject, smtpobject)
   mail to: receiverobject.email, subject: "Welcome!",
     delivery_method_options: { user_name: smtpobject.smtp_user,
                             password: smtpobject.smtp_password }

end

this will ensure that your settings from environments/production.rb will be override.

we can get an array of email sents through Action Mailer . mostly used in progress bar like functionality like suppose in view we wanted to show a progress bar with the count of how many emails has been sent then we can get this through this ActionMailer::Base.deliveries method


No comments:

Post a Comment