问题
I successfully send Mails via SMTP using my Rails App and my Postfix Server. Now I need to move to an Exchange: Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 that has POP3 and SMTP support enabled.
I use actionmailer 1.2.5 and am not able to successfully login to the server while trying to send a mail.
In case I use Mail.app sending and recieving works fine as long as I change the authentication schema to "Password". Checking the server looks like so:
READ Nov 18 10:37:00.509 [kCFStreamSocketSecurityLevelNone] -- host:mail.my-mail-server-domain.com -- port:25 -- socket:0x11895cf20 -- thread:0x11b036a10
250-mail.my-mail-server-domain.com Hello [xxx.xxx.xxx.xxx]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK
WROTE Nov 18 10:37:00.852 [kCFStreamSocketSecurityLevelNone] -- host:mail.my-mail-server-domain.com -- port:25 -- socket:0x11895cf20 -- thread:0x11b036a10
AUTH LOGIN
READ Nov 18 10:37:01.848 [kCFStreamSocketSecurityLevelNone] -- host:mail.my-mail-server-domain.com -- port:25 -- socket:0x11895cf20 -- thread:0x11b036a10
235 2.7.0 Authentication successful.
So authentication method :login seems to be properly supported. Now when it comes to my configuration for actionmailer it looks like so:
ActionMailer::Base.server_settings = {
:address => "mail.my-mail-server-domain.com",
:port => 25,
:domain => "my-mail-server-domain.com",
:authentication => :login,
:user_name => "myusername",
:password => "mypassword"
}
And I get authentication errors over and over. I also tried to change
:user_name => "my-mail-server-domain.com\myusername"
:user_name => "my-mail-server-domain.com\\myusername"
:user_name => "myusername/my-mail-server-domain.com"
:user_name => "myusername@my-mail-server-domain.com"
but nothing works. Can anyone help me?
Regards. Jason
回答1:
i think you need to add
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:domain => "my-mail-server-domain.com",
:address => "mail.my-mail-server-domain.com",
:port => 25
:authentication => :login ,
:user_name => 'myusername',
:password => 'mypassword',
}
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.default_content_type = "text/html"
or try changing your port. usually port 25/26 is blocked to send emails, and some email providers are refusing to receive email from port 25 that uses localhost smtp. Or maybe your internet provider is blocking port 25. if it still doesn't work you could write the errors here.
来源:https://stackoverflow.com/questions/1754819/actionmailer-and-exchange