Why would I use Mandrill as opposed to the built in ActionMailer? - ruby-on-rails

I've read the documentation for both services but I just am not seeing the benefits of using Mandrill as opposed to Rail's ActionMailer for transactional services. I can already customize emails with ActionMailer and send them out. Is the difference between the services a matter of volume? If so, at what point would I need to switch out ActionMailer for Mandrill?
This tutorial here is a little bit more confusing because it integrates ActionMailer with Mandrill. MailChimp/Mandrill tutorial
Can someone help me explain the difference? For my real life purpose, all I want to do is send emails to people to reverify their accounts and according to my research that would seem like a job suited for MailChimp.

Basically mailchimp/mandrill is a Saas offering they offer you a SMTP services like the amazon SES service.
ActionMailer is a part of Rails that allow interfacing with a mailing system.
from its docs you can see the following options:
Defines a delivery method. Possible values are:
:smtp (default), can be configured by using config.action_mailer.smtp_settings.
:sendmail, can be configured by using config.action_mailer.sendmail_settings.
:file: save emails to files; can be configured by using config.action_mailer.file_settings.
:test: save emails to ActionMailer::Base.deliveries array.
where the default for SMTP is using localhost (assuming your own server run a SMTP server.
In your case you should use mailchimp to deliver you message, but you will still need to use actionMailer to create the message/email itself.
It reduces complexity by allowing you to offload the sending part.

For the use that you're describing, it sounds like action mailer is just fine.
However, if
You're not interested in managing a mail server
Don't want to spend time trying to figure out if an email was actually sent (based on a client reports)
Want to impose mail quotas easily per client
Then I would recommend mandrill. We've started using it for mailing and haven't looked back since. You get reliability, expert advice / mail system setup and ultimately the biggest feature for me: delivery reporting.
Mandrill allows you to interact with their system via REST API or SMTP. If you're using their SMTP, you would still need to use ActionMailer to deliver email. All you need to do is setup your production.rb file to point to Mandrill:
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 25, # ports 587 and 2525 are also supported with STARTTLS
:enable_starttls_auto => true, # detects and uses STARTTLS
:user_name => "username",
:password => "password", # SMTP password is any valid API key
:authentication => 'login', # Mandrill supports 'plain' or 'login'
:domain => 'example.com', # your domain to identify your server when connecting
}
So to summarize; in my opinion it's not a matter of volume, rather convenience.
I hope that helps.

Related

Receive Mails with Rails

I would like to scrap mails from a MailBox, this is the situation:
It's about a Technical support with a Ticket System.
A client make a demand on the contact form on the website,
The ticket have a page with a chat and a task list made by the admin in charge of the ticket, so a link to this page is sent to the client who made the demand,
Then when the Admin answer to the ticket in the chat, a mail is sent to the Client, everything to there is ok, the problem is that when the client answer to this email, the content of the mail must be scrapped and added to the database to be seen in the Ticket Chat.
So the Idea is that the Client Can follow the progress of his Ticket by mail instead of going to the ticket page.
I've tried MailMan, but that didn't work, the deamon was starting and then crashed after a couple of minutes whitout scrapping anything, I don't use SendGrid but a private SMTP server so I can't use the Grabber gem of this service.
I'm running Rails 5, my DB is in PostGre, and I'm using ActionMailer as mailing system.
I'm running out of ideas about how to make this feature..
I hope my question is clear enough and my English not too bad.
I suggest you to make an email(any popular provider except gmail) box and configure it to use the pop server. To read it from box use the mail gem.
Mail.defaults do
retriever_method :pop3, :address => "pop.supermail.com",
:port => 995,
:user_name => '<username>',
:password => '<password>',
:enable_ssl => true
end
Then make a daemon to read all income emails and save it to the database, mail gem is just a wrapper around Net::POP3 ruby library and it is super useful for read\receive\parse\build mails.
The ActionMailer here is not a helper for you, it is very handy only for send mails and it does nothing to recieve mail.

configuring rails to send email via the microsoft live smtp server

There is a lot of information in rails about setting up rails to work with gmail and I have done this for a personal (e.g. myemail#gmail.com ) website.
Now unfortunately google apps for businesses no longer offers free mail hosting but as it says here apparently outlook do.
so I followed the instructions, changed my DNS MX records and everything and set up smtp (similar to the google version like so )
this gives me (eg from here):
config.action_mailer.deconfig.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.live.com",
:port => 587,
:domain => 'mydomain.com'
:user_name => 'username',
:password => 'mypass',
:authentication => 'plain',
:enable_starttls_auto => true }
ahh. I have finally solved this, I figure I'll post it to save somebody else the hassle. I had massive headaches trying to get this microsoft server to send from any address, my solution is now to use mandrill it's easy to configure and free for less than 12k emails per month.
(DISCLAIMER: I have no connection to Mandrill, please let me know any tips to allow the microsoft server to work, I couldn't and half a day was enough for me)
I have basically identical settings as you but mine is working. I'm guessing your user_name is wrong, it should be
:user_name => "username#mydomain.com"
and also make sure you've at least logged in once to your newly created account to activate it

Basic Confusion about ActionMailer RoR

I'm fairly new to Ruby on Rails and actually entirely new to website mailing. In a lot of example tutorials I see a "from" object assigned to, for example, "new#example.com". When I setup the emailing functionality on a localhost the RoR command prompt says that everything finished fine even when I keep "new#example.com" as the from object. Can I actually mail from a localhost port? What would I have to put as my "from" address in order to actually send mail from the my local web application? Just a regular email I have? How would it be authenticated to ensure that the "from" address is actually the real address?
It seems a really fundamental concept and I understand all the model/view/controller actions that have to be done to make it work but I'm confused I guess as to how it actually works
In general the from field can be anything.
Some mail servers may take action if they think that you are claiming to be someone you are not, such as blocking mail or marking it as spam (via mechanisms such as DKIM or SPF). These are done at the domain level, ie the mail server tries to work out whether the server talking to it is allowed to send email claiming to be from #example.com.
Other mail servers mail just silently rewrite your from field if they know who you are, for example if you are talking to the gmail smtp servers and have authenticated as bob then the from field will be set to bob#gmail.com, unless it is already set to an email address gmail knows you own.
By default, in development rails doesn't try and send email at all. For it to send email you need to configure the deluvery_method, usually this involves either setting it to :sendmail (if you have an appropriately configured instance of sendmail running locally) or setting to :smtp and also providing details of an smtp server to use.

How do I make ActiveMailer always mail me?

I use ActiveMailer with a 3rd party mailing provider. To develop my app, I want to actually see the emails that come in, as a user would, in my email client.
So in development mode, instead of disabling email, I want my app to send the mails, but change the "to" field so that every email is sent to me. Is that possible?
Update: I want to test the full route my email takes: going through my ESP, arriving in my inbox, viewing it in gmail. I'm not looking to just test that an email is created.
I personally recommend letter_opener by Ryan Bates, however, if you actually want to deliver the mail instead of just viewing it in the browser, there are a number of plugins available that others have already listed. No one, however, has mentioned that you can very easily accomplish this using Interceptors.
Create a new initializer in your config/initializers directory in your Rails app:
# config/initializers/development_mail_interceptor.rb
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.subject = "[#{message.to}] #{message.subject}"
message.to = "YOUR_EMAIL#gmail.com"
end
end
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
This leverages the power of an interceptor on your app. It doesn't configure anything, but rather changes the envelope on the message, altering the to and subject fields. Replace YOUR_EMAIL with the correct value.
The self.delivering_email(message) method is invoked by ActionMailer. You are hooking into that method and override the message envelope.
Finally, you register that interceptor iff we are currently in the development environment.
Be sure to restart your server, and all your mail (in Development) will actually be sent to your email.
Save yourself some trouble and run MailCatcher. MailCatcher is a simple SMTP server that just grabs outbound email and gives it to you in a simple web interface. Install MailCatcher, add this to your environments/development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :host => 'localhost', :port => 1025 }
Start MailCatcher when you start your Rails server (or use Foreman or something similar to deal with it), and then go to http://localhost:1080/ to see the email that your application is sending out.
You may consider checking out something like MockSMTP (OS X); instead of modifying your "to" fields, you instead set the mail server for dev mode to the "fake" SMTP server created by the app, and from then on ALL emails (sent to anyone) go instead to the app.
I've never used it myself, but I remember seeing that the devs at 37signals use it.
On other operating systems, you may consider one of the following projects:
letter_opener by Ryan Bates - popup a new browser window when an email is sent
MailCatcher (mentioned by mu is too short) - runs a fake SMTP server and a web-based interface for viewing mail sent to it
mailtrap - similar to MockSMTP, has both a mock SMTP server and also a separate viewer program
As much as I like this answer, I went with a different option.
Use the mail_safe gem! As well as providing the functionality from sethvargo's answer, it doesn't require any work other than adding the gem, and it automatically figures out who to email from their .gitconfig.
One important note that I rarely saw mentioned when researching this is that you must use deliver, not deliver!. The latter doesnt call interceptors (though apparently it still calls observers, if that's helpful).

ActionMailer doesn't send any email, but gaves no error - in AWS EC2

Im trying to use ActionMailer in a Rails2 app in a AWS EC2; I have configured it, I created the model, the views and everything, and when I try to send an email, it gaves me no error, but the email never reached the final user.
This is my configuration in environment.rb
config.action_mailer.default_url_options = { :host => 'mysite.com' }
config.action_mailer.delivery_method = :sendmail
And everything is like in the books. I don't know what to do, I have installed Devise and when I try to send emails (for user confirmations or things like that) it works. I put the configuration of action_mailer to work with SMTP of GMail, and it works for me but Devise throw me errors...
What should I do? thanks in advance!
It is usually better to use the external SMTP server because there are strict limitations sending emails from AWS EC2 machines.
We have successfully used Devise and SMTP together in some of projects at BitNami. What errors are you getting?
You may also consider using Amazon email service.
There are some gems out there to add support for it like amazon-ses-mailer.

Resources