Using ActionMailer with a company Gmail account

2019-05-02 11:55发布

问题:

I'm not sure if this belongs in server fault or here feel free to move it if it makes more sense somewhere else. I've seen the examples for setting up the smtp settings and using ActionMailer with Gmail and confirmed that they work for me.

Basically it looks like this for me:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :user_name            => '<username>',
  :password             => '<password>',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }

What I need to do now is to send an email to an address that isn't a plain Gmail account and yet, at it's core, is Gmail. My company uses whatever google's email service that allows you to use gmail but for the addresses to be listed as username@my.company.com rather than @gmail.com. I know for a fact that you can't simply log into our mail at the main gmail site so I assume our domain is different. Or something.

At the moment, when I simply use my own company user/pass I get an error message telling me that the user/pass was wrong. But I'm guessing the issue is that I'm trying to mail from the gmail variant of my username.

I have confirmed that our smtp server, as far as Thunderbird is concerned, is the normal gmail smtp, that our port is still 587, and that we are using TLS. What do I need to change here so that I can send an email to one of these addresses? Thanks.

回答1:

I have my own domain setup at google for mail, the url to log into that directly is

http://mail.google.com/a/my.company.com

My rails app that sends mail through that account, has

:domain => "my.company.com"

as well as all the other fields you have.

"<user_name>" needs to be the whole email address, not just the user name.



回答2:

:address  => 'smtp.gmail.com',
:port   => 587,
:domain => 'busiess.com',
:user_name => 'username@company.com',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true