Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMTP settings for Office 365 in Rails application

I have an Office 365 mail account with Godaddy. I'm trying to setup the SMTP settings for my Rails app:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address              => "smtp.office365.com",
:port                 => 587,
:user_name            => ENV["OFFICE_USERNAME"],
:password             => ENV["OFFICE_PASSWORD"],
:authentication       => 'login',
:domain               => 'example.com',
:enable_starttls_auto => true  }

but when I test those settings by submitting a message from my contact page, I get this error message:

550 5.7.1 Client does not have permissions to send as this sender

How to set up the SMTP settings for an Office 365 account in a Rails application?

like image 983
Toontje Avatar asked Nov 30 '22 19:11

Toontje


1 Answers

I found the answer to this question here: http://www.brownwebdesign.com/blog/connecting-rails-to-microsoft-exchange-smtp-email-server

Relevant parts:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address        => 'smtp.office365.com',
    :port           => '587',
    :authentication => :login,
    :user_name      => ENV['SMTP_USERNAME'],
    :password       => ENV['SMTP_PASSWORD'],
    :domain         => 'congrueit.com',
    :enable_starttls_auto => true
}

Then:

make sure the from: email address matches, from domain, and user/pass.

Not my work just copy and paste of relevant information that worked for me.

Addition for 2021:
Since April 2020, you have to enable SMTP AUTH in your office 336 organisation and the mail account you are using.
See Enable ... SMPT AUTH at docs.ms. In this document, the explanation is missing that both parts must be enabled.

like image 79
gkulasik Avatar answered Dec 04 '22 23:12

gkulasik