Skip to main content

How to use Action Mailbox in Rails 6 Discussion

General • Asked by Chris Oliver

This is great!

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

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. [email protected])
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

Interesting. Thanks!

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

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


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

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!

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

can you please make some more with twillio?

thanks in advance.


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?

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


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.