Rails 6 Action Mailbox and Gmail Integration How To - ruby-on-rails

Rails 6 comes with Action Mailbox now. The documentation and community do not have great resources on how to integrate various services outside of the most common such as SendGrid.
Assuming a person uses Google's Gsuite Gmail:
How could they integrate that with Action Mailbox?
Would one use Gmail's API, or would that not be appropriate for Action Mailbox?
If Gmail doesn't work, what is different about SendGrid that makes it integrate appropriately?

Action Mailbox is built around receiving email from a Mail Transfer Agent (MTA) in real time, not periodically fetching email from a mailbox. That is, it receives mail sent via SMTP, it doesn't fetch mail (using IMAP or POP3) from another server that has already received it.
For this to work it is dependent on an external (to Rails) SMTP service receiving the email and then delivering the email to Action Mailbox. These external services are called "Ingresses" and, as at the time of writing, there are 5 available ingresses.
Of the five, four are commercial services that will run the required SMTP servers for you and then "deliver" the email to your application (usually as a JSON payload via a webhook).
Mailgun - scroll down to "Inbound"
Mandrill
Postmark
Sendgrid
You could already use those services in a Rails App and handle the webhooks yourself but Action Mailbox builds a standardised set of functionality on top. Almost like a set of rails to guide and speed the process.
In addition, the fifth ingress is the "Relay" ingress. This allows you to run your own supported MTA (SMTP server) on the same machine and for it to relay the received email to Action Mailbox (usually the raw email). The currently supported MTAs are:
Exim
Postfix
Qmail
To answer your specific questions about Gmail:
How could they integrate that with Action Mailbox?
They couldn't directly. They would need to also set up one of the 7 MTAs listed above and then somehow deliver the emails to that. The delivery could be accomplished with:
Forwarding rules managed by the user at the mailbox level
Dual delivery, split delivery or some other advanced routing rule managed by the admin at the domain level
Would one use Gmail's API, or would that not be appropriate for Action Mailbox?
Even if there were a way to have Gmail fire a webhook on incoming email (I'm not aware of any special delivery options outside the advanced routing rules above), there is currently no way to connect that theoretical webhook to Action Mailbox.
If Gmail doesn't work, what is different about SendGrid that makes it integrate appropriately?
Sendgrid (to use your example, the others work more or less the same way) offers an inbound mail handling API. Just as importantly, the Rails Team has built an incoming email controller to integrate with that API.
Given the lack of Gmail APIs and the lack of a Rails ingress controller, the only way I can think of that you could connect Action Mailbox to an existing Gmail mailbox would be for some other bit of code to check the mailbox, reformat the fetched email and then pose as one of the supported MTAs to deliver it to Action Mailbox.
It would be an interesting exercise and would possibly become a popular gem but it would very much be a kludge. A glorious kludge if done well, but a kludge nonetheless.
Another option would be to leave your example.com domain delivering to Gmail as normal and set up another domain for your Action Mailbox emails. You could use a separate domain, example.org, or a subdomain, app.example.com.
This would involve setting up one of the 7 supported SMTP servers and pointing the MX records for example.org or app.example.com at those servers.
Bonus trivia: Another name for an MTA is a Mail eXchager, hence the name for a DNS mail record is an MX record.

To integrate IMAP with Rails, have a look into the greate mail_room Gem
It's a daemon that you can start alongside your app, which listens onto couple of IMAP inboxes, and then convert those into either a Sidekiq Worker or push it via http to your app.
It's used by Gitlab for their mail interactions (Answer to thread, create issue by writing to an email).
They also have a section on how to integrate with ActionMailbox.

If you were dead set on doing this, Gmail has had IMAP IDLE (push) support since day one.
It would be quite easy to write a small daemon that watches a Gmail inbox and calls the rails action mailbox webhook endpoint with a properly formatted JSON payload.

Related

Using sendgrid with rails so I can send emails from Google Cloud Platform on port 465. Isnt working

Its my first time playing around with sending emails in an application. I'm using an instance on the google cloud platform and found out that they block sending emails form port 465. They have an work around solution which is using a third part to send the emails. I decided to go with sendgrid. But there are a few different options for setting it up and I'm not sure which is the one I'm supposed to use for CGP to allow me to send emails using SSL.
I followed this tutorial by sendgrid but I still have the instance blocking port 465. Am I supposed to do it a different way? If so what am I supposed to do?
To send email via SendGrid from gcp, you need to use port 2525.
See this link for more information on using SendGrid.

Features of Mandrill API

I am new to Mandrill and its integration. Can anyone help me to figure out the advantages of using Mandrill? What can be done using Mandrill other than sending messages and tracking them?
Mandrill has many uses. You might have seen those on their website itself. Actually its a Mail Transaporter like PHP mailer, but it uses their own server for sending mails.
As said on their website,
Mandrill runs on a globally distributed infrastructure that can
deliver emails in milliseconds.
This is because when you send a mail through their SMTP or send.json (API) method, the send mail possibly see the fastest path algorithm to deliver a mail. That's why it take milliseconds to deliver. They have ~7 different mail servers worldwide for this.
Major Features,
Sending mails fastly than our own server using PHP Mailer.
Sending mails via pre-designed templates which can be reusable by the merge vars we're using.
Support multiple language platforms like, cURL, JSON, Python, PHP, Ruby, Nodejs, Dart and also their depending frameworks.
It tracks clicks from the mail we sent. For Ex: each and every url link in our sent mails is redirected only after tracking from mandrillapp site. This enables mandrill to track the no of opens in a mail and track analytics.
Through mandrill we can construct our own mail sending application or integrate into an existing application.
It's mostly used for Transactional Messages like functions like welcome mail, forgot password, cart details and etc.
It can be integrated into other shopping cart web applications.
Their api call works on even in the developer environment.
Lesser spam.
Verified domain options like DKIM and SPF settings. This enables the mails to identified by major email providers like gmail, google, etc.
It can be used as SMTP version and can be integrated into major SMTP applications.
Reports: Demographics of email send, Compare status, Which url in our mails has been clicked and no of counts.
Setup rule for delivering emails.
A/B testing, custom SMTP headers, Inbound domains and etc.
There are many other features in developer perspective. If you mention in which platform you're trying to use mandrill addditional details can be provide.
Hope this might help you.
To name a few, You can
1) use templates to do A/B testing ( which allow you to experiment with different templates, and end up with something which is effective).
2) use Embedded images , which will reduce the chance that your emails will end up in spam.
Hope this helps,

Way to up incoming and outgoing mail for a custom mobile app

I am used to building apps in larger infrastructures. In a startup, how do I setup SMTP for a mobile app? Is there a place I can use for hosting this?
There are a couple of possible approaches:
One option is to not attempt to interface with SMTP/IMAP/POP servers directly in your app. You can, alternatively, send emails from your app via MFMessageComposeViewController, which gives you a standard compose email user interface. This is very easy to do.
To handle inbound emails you can let the user receive their emails via the standard Mail app (that way users don't have to go to different places to receive their emails). You integrate inbound emails with your app using a custom URL scheme. You can then send the user an email using this custom URL scheme, and if they get the mail on their iOS device and have that app installed, when they click on the link they will be taken to your app, passing it information from the URL in the email.
For example, if you defined a custom URL scheme of yourapp://, you can just include a hyperlink to that URL in your email (or text message or your web site), and if the user is on their iOS device, when they click on that link, they'll be taken to your app. If you google "iOS custom URL scheme tutorial", you'll see examples of the plist entries you need to make in your app for it to respond to a custom URL scheme. The Implementing Custom URL Schemes reference shows you what sort of changes you need to make to your app delegate to actually pass data in your custom URL to your app.
Alternatively, you can (a) sign up with any Internet Service Provider (ISP) that offers mail hosting; (b) write an app that sends email by connecting to that ISP's SMTP server; and (c) retrieve email by connecting to that ISP's IMAP or POP servers. Clearly you'll have to pay fees to the ISP, the quality of your app is linked to the quality of the ISP you partner with (so pick a good one), and you'll have to do your own SMTP/IMAP/POP integration in your app (and you'll have to write your own code to do that or use a third-party library for that, as this is not standard Cocoa Touch functionality). In my opinion, you'd need a pretty compelling business case to go down this road, though it can be done.
You could avoid email altogether, and develop a web service for letting the users send and receive messages. (This might make sense if the app is just sending messages between users of your app, for example.) Again, you'll have to contract with an ISP for web hosting, and you'll of course have to undertake the non-trivial exercise of writing your web service code. But this is architecturally cleaner than integrating with SMTP/IMAP/POP servers if the purpose of your app to facilitate communication between users of your app.
You haven't provided enough information for us to assess which approach best suits your situation.

We need a mail client for sending notification emails via ActionMailer

We need to send out thousands of emails per day via ActionMailer in our Rails app. These will be sent upon receipt of user interaction in our app. Gmail Enterprise limits at 2,000 per day, this simply will not be enough for us, and thus we cant use it.
GMail isn't intended or appropriate for large amounts of bulk mail. At the volumes you want to send, you need a dedicated provider designed for buik mailings. There's plenty of providers that do this, but SendGrid is a popular option, and can handle very large volumes.

Notification Emails Using Mailchimp

I am new to mailing with webapps. I looked around and found Sendgrid and Mailchimp. I can see that sendgrid's developer section has a simple smtp url that i should be able to use simply. However i don't find any such thing on Mailchimp. I am wondering how I can use mailchimp to send notifications like User registration or confirmation notification (not necessarily large number of emails blasted altogether but individual notification emails). Right now my application is set to use sendmail in rails.
Can anyone give me clues as to how I can use Mailchimp as the service for sending notification like emails and not mass emails. So far it seems like mailchimp may be more for just mass emails, is that correct?
Thanks
Sendgrid is a simple SMTP provider and relay. Mailchimp is more designed for email marketing using their toolchain. I would reccomend that you stick with sendgrid for simple notification messages but use Mailchimp for email campaigns and complex notifications.
So yes you initial guess is correct that it the two services are to be used for different things. However if you really want to use Mailchimp for email notificatons I would be more than happy to dig up some information for you.

Resources