Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to use Action Mailbox in Rails 6 Discussion

This is great!

Can action mailbox be used with a gmail account or does it have to be one of the services listed?

Reply

https://github.com/rails/rails/blob/6-0-stable/actionmailbox/app/controllers/action_mailbox/ingresses/relay/inbound_emails_controller.rb

stmp protocol supported.

Gmail's Default SMTP Settings
Gmail SMTP server address: smtp.gmail.com
Gmail SMTP username: Your Gmail address (e.g. example@gmail.com)
Gmail SMTP password: Your Gmail password
Gmail SMTP port (TLS): 587
Gmail SMTP port (SSL): 465
Gmail SMTP TLS/SSL required: yes

action mailbox guide: https://edgeguides.rubyonrails.org/action_mailbox_basics.html#introduction

Reply

Interesting. Thanks!

Reply

Sorry - I can't see how this should work. What I learned is, that gmail does not allow piping to a server, only forwarding to a different mail server. So for me it looks like it is not possible to use a gmail account for action mailbox. Please correct me if I'm wrong!

I would really appreciate a setup tutorial for action mailbox without any commercial service provicder.

Best regards,
Andreas

Reply

I second the request for a full gmail action mailbox example.

Reply

I'm curious about testing with Gmail as well. At about 17:03, Chris mentions "using a tool like ngrok to expose your Rails app to the public internet," allowing you to "go to Gmail and send emails to your actual email address, routing them to your local Rails app for testing."

I set up my Rails app to route all emails, and configured ngrok. I tried sending to the the ngrok domain, "test@example.ngrok.io," but the delivery failed. Not sure if this is the right approach, but I wasn't sure how else to use ngrok to send mail to my local app. Any insight is appreciated!

Reply

Little late to the party, but I'll add my voice to those hoping for a full gmail action mailbox example, especially in production.

Reply

How difficult, assuming it’s possible, would it be to adjust this for receiving replies via SMS (to use the episode’s example)?

Reply

You can definitely do it, but you wouldn't be able to use ActionMailbox for that. You'd want to use something like Twilio and setup a controller to receive the webhooks they send. I've been planning on doing some Twilio stuff, so I'll have to do that soon!

Reply

Hi Chris, i just got your email from twillio. superb.

can you please make some more with twillio?

thanks in advance.

Reply

How come the mail and inbound_mail objects are available to all instance methods?

This question is not only related to ActionMailbox, but i will still post it here as i never saw a similar use of "local variables" before your episode on ActionMailbox, altough i am not sure if those are actually "local variables".

In your replies_mailbox.rb you have the following code:

class RepliesMailbox < ApplicationMailbox
  def process
    return if user.nil?
  end

  def user
    @user =|| User.find_by(email: mail.from)
        # the mail object is available here
  end

# …
end

Somehow the mail and the inbound_mail objects seem to be available to all instance methods of RepliesMailbox. This is an interesting functionality because you don't have to define all methods like def user(mail), def discussion(mail), def discussion_id(mail), if they all refer to the same mail object anyway.

I am not sure if the mail and inbound_mail are actually "local variables" and maybe i am missing out on a fundamental knowledge of variable scope. But how come you can access those objects throughout all methods? Can this way of "reusing" variables be used in all Ruby / Rails code?

Reply

Same way params is available to all methods in your controller. It's simply a method defined in the parent class.

Reply

Hi,
I'm struggeling getting it right. I can follow the explanation and already have an application coded. The thing I don't really understand is: How does my mail server deliver the mails to my mailbox application? Is it really "just" a single command like state here: https://github.com/rails/rails/blob/6-0-stable/actionmailbox/app/controllers/action_mailbox/ingresses/relay/inbound_emails_controller.rb#L41-L44

Will this command be executed for every mail on it's own or is this something one can configure in the mailserver? I - sadly - have no experience with mail servers.

Kind regards,
Ben

Reply

Most people use Sendgrid or another service to handle mail servers. If you haven't done it before, you should use them and their inbound email functionality. It'll save you a ton of time trying to figure things out.

Reply

Yes - it mostly is just this line wich "formwards" the mail to your application.
I struggled most getting User/Permissions right so that the process which is running the mailserver can execute the bin/rails in the App Environment which will most likely be a different user.
Any guides/best practices appreciated...

Regards,
Andreas

Reply

Alright, thanks for your responses! I will have a looking into Sendgrid and give it a try.

Ben

Reply

I think I've missed something, but I'm attempting this tutorial and I can't seem to get any of my InboundEmails to move from pending to processing. It kinda just happened on its own in the video from what I can tell, but my inbound emails are not moving past the pending stage. I'm not sure where to look since I didn't see any mention of configuration in the video. Might have missed it though.

Reply

Make sure your background workers are processing the action_mailbox_routing and action_mailbox_incineration queues.

Reply

Just getting back to this. Is this something that I put in development.rb/production.rb? This says it defaults to action_mailbox_routing, and I don't see it specified anywhere in my project, searching for config.action_mailbox.queues.routing. I'll keep investigating myself and let you know if I figure it out

This is what I have in my ApplicationMailbox class

class ApplicationMailbox < ActionMailbox::Base
  # routing /something/i => :somewhere

  routing RepliesMailbox::MATCHER => :replies
end
Reply

Nah, you'd just add those queues to Sidekiq, delayed job, etc.

Reply

Hey, I'm having the same problem. I followed the tutorial and added to my sidekiq.yml file the following :
:queues:

  • mailers
  • default
  • action_mailbox_routing
  • action_mailbox_incineration
  • active_storage_analysis
  • active_storage_purge

But my InboundEmails are still processing. When I look at the logs, it seems that I never go to the process method. Do you have any ideas of what is happening ?

Reply

Hi Chris, Please help me. I didn't get the point where you are querying for mail. I mean fetching incoming mails.

Reply

Hi Chris, I was wondering if you are aware of any way to determine email threads (parent/child relationships) using ActionMailbox?

Reply

Emails have a message-id and in-reply-to header that you can use for tracking that info. I haven't played with it too much, but you'd probably want to save the message-id after an email is sent, and always make sure you include the in-reply-to as necessary.

Reply

Hi Chris,

I am am able to parse inbound emails in development. But I am having trouble setting this up in production. The password I set here is it the Sengrid API key or a password I make up?

action_mailbox:
ingress_password: ...

The password in the URL is it just the password used above?

https://actionmailbox:PASSWORD@example.com/rails/action_mailbox/sendgrid/inbound_emails

Reply

You create a password in the credentials (make one up) and then use that password in Sendgrid's webhook URL. That way Rails can verify the POST request came from Sendgrid (and not someone trying to abuse your app).

Reply

Thanks for the response. Still running into some issues. I contact the support team at SenGrid and they said the following:

Thank you for your patience, our data is pulling a few bounces from the parse, for instance email: test@parse.bindsoft.io event: parseapi from: ryan faraone ryanfensurco@gmail.com msgid: 4b55d4f8-3cbb-11eb-be85-8a2d3223e1ca reason: 500 Can't connect to bindsoft.io:443

any idea how to fix this?

Reply

Hi Chris, I contacted Sengrid support and it appears as though my inbound parse webhook is not working correctly and they are receiving and error posting to it. The URL I have set up is:

https://actionmailbox:password123@bindsoft.io/rails/action_mailbox/sendgrid/inbound_emails
I've been struggling for quite some time to figure this out.
Do I need to create a route in routes.rb with this POST routes?
Any help would be greatly appreciated.

Reply

Here is a tough one. How do you stop the out of office replies coming through on these reply emails or is that something that is the downside of having the ability to reply to post via email?

Reply

You could write a filter to try to skip those, but yeah that's generally something you have to always deal with having this feature.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,796+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.