I am trying to send mail from MS exchange server but I am getting error as
`check_auth_response': 503 #5.3.3 AUTH not available (Net::SMTPAuthenticationError)
The code I used to send mail is
require 'net/smtp'
require 'mail'
smtp = Net::SMTP.new('mycompanydomain',25)
smtp.start('mycompanydomain', 'name#company.com', 'pwd',:plain) do |smtp|
# code to send mail
end
Note: It works fine with Gmail account but fails for company account.
Any help would be useful.
Are you sure that your server supports AUTH? You can find out by:
If the connection is not encrypted:
telnet mycompanydomain 25
ehlo testing
It should respond with something that that says AUTH PLAIN in it. If it doesn't, your server does not support plain auth, it may list other auth methods. You may need to set it to one of them.
More information http://qmail.jms1.net/test-auth.shtml
Related
Folks,
Can anyone provide a working example of how to do SSL client authentication in ruby 1.8.7? For the record, I am attempting to use a GoDaddy certification to perform an authenticated post request to the Windows Phone push notification service. In this case, my command-line client is using a certificate like an API key or bearer token.
I supply GoDaddy a mydomain.com.key file, and GoDaddy supplies me with a gd_bundle.crt file and a mydomain.com.crt file.
On my Net::HTTP object, I have set these parameters:
my_cert = File.read(File.join(File.dirname(__FILE__), "mydomain.com.crt")) # from godaddy
my_key = File.read(File.join(File.dirname(__FILE__), "mydomain.com.key")) # i made
http.use_ssl = true
http.cert = OpenSSL::X509::Certificate.new(my_cert)
http.key = OpenSSL::PKey::RSA.new(my_key)
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
But the push notification service continues to report a 403 error saying "You do not have permission to view this directory or page using the credentials that you supplied".
Since someone out there is doing push successfully I assume the way I have configured my Net::HTTP object in ruby is incorrect. Does anyone have sample code for how I can use ruby to perform SSL client authentication?
The error that I get is:
Net::SMTPFatalError: 550 5.7.1 Unable to relay for you#test.lindsaar.net
I am using mail-2.3.0
With Ruby 1.9
on windows XP.
The exact code I used is:
require 'rubygems'
require 'mail'
Mail.deliver do
from 'me#test.lindsaar.net'
to 'you#test.lindsaar.net'
subject 'Here is the image you wanted'
end
I don't understand what I am missing. Thanks for your help.
The error message comes from your SMTP server. Although this message can have many causes, it is most likely you forgot to provide the necessary authentication data to your SMTP server.
Taken from http://www.eudora.com/techsupport/kb/1593hq.html:
Most Internet Service Providers restrict access to their outgoing mail
servers to prevent SPAM from being sent through their mail servers. If
you are getting the "550 Relay Denied" error message, the outgoing
mail server cannot verify who you are and will not allow you to send
mail.
To configure Mail you have to prepare your own SMTP connection. See https://github.com/mikel/mail/wiki/Sending-email-via-google-smtp for an example.
You can get your username/password from your ISP (the one providing the SMTP server)
Here's my simple test program (using ActionMailer 3.0.8, Ruby 1.9.2p180 Mac OS X):
require 'rubygems'
require 'action_mailer'
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "my_exchange_server",
:port => 25,
:domain => 'my_domain.org',
:authentication => :login,
:user_name => 'my_user',
:password => 'my_password',
:enable_starttls_auto => false
}
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.default :from => 'from_email#my_company.com'
m = ActionMailer::Base.mail :to => 'to_email#my_company.com', :subject => 'this is a test', :body => 'this is a test'
m.deliver
Trying various authentication types I get the following errors:
:plain error:
smtp.rb:966:in `check_auth_response': 504 5.7.4 Unrecognized authentication type. (Net::SMTPAuthenticationError)
:login error:
smtp.rb:972:in `check_auth_continue': 504 5.7.4 Unrecognized authentication type. (Net::SMTPSyntaxError)
:cram_md5 error:
smtp.rb:972:in `check_auth_continue': 504 5.7.4 Unrecognized authentication type. (Net::SMTPSyntaxError)
No authentication error:
protocol.rb:135:in `read_nonblock': end of file reached (EOFError)
Any ideas?
Check what authentication schemes are enabled
It could be: none, plain, login, cram_md5, NTLM, StartTLS
Using Telnet to connect to Exchange 2003 POP3 mailboxes and using SMTP to send e-mail for troubleshooting purposes
http://www.msexchange.org/tutorials/telnet-exchange2003-pop3-smtp-troubleshooting.html
Scroll down to: Connecting to SMTP
What did EHLO return?
"250-AUTH LOGIN" or "250-AUTH=LOGIN" indicate that you need to authenticate.
"250-AUTH" (with nothing else following on that line!) seems to indicate that you should NOT authenticate yourself! Otherwise you will get the error:
"504 5.7.4 Unrecognized authentication type"
How to properly access Exchange
Good resources that should help you to understand and troubleshoot it.
The EHLO verb and SMTP extensions
http://cr.yp.to/smtp/ehlo.html
The AUTH Command
http://www.samlogic.net/articles/smtp-commands-reference-auth.htm
How to Use Telnet to Send SMTP Email to Exchange 2007 and 2010
http://www.expta.com/2010/03/how-to-use-telnet-to-send-smtp-email-to.html
Using telnet to test authenticated relay in Exchange
http://www.dasblinkenlichten.com/?p=190
How you could change Exchange to fix the problem
(instead of changing how you access Exchange)
How to enable auth login on smtp server exchange 2010
http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_26538583.html
How to Enable "Auth Login" authenticaton on Exchange
http://www.advancedintellect.com/post/2011/03/02/Exchange-2010-and-SMTP-settings.aspx
Error in establishing SMTP connection, Error: 504 5.7.4 Unrecognized authentication type
(how to change the Exchange 2010 configuration to "accept mail from third part product" as mentioned by Anil K Singh)
http://social.technet.microsoft.com/Forums/en-US/exchange2010/thread/93ad411a-0da2-4494-a45e-8cbb793aeca9/
Redmine specific
Helpful for Ruby on Rails
How to configure Redmine to mail to MS Exchange server
http://www.redmine.org/projects/redmine/wiki/HowTo_configure_Redmine_to_mail_to_MS_Exchange_server
"MS Exchange will not require authentication information for outgoing (SMTP) email"
My configuration file is still at config/email.yml (in Redmine 1.2)
Helpful troubleshooting tips for Ruby on Rails code
See answer from firien
How to use ruby-ntlm in case Exchange requires NTLM
Unrecognized authentication type when doing an Auth to Exchange from Rails
How to use the TLS option
http://www.redmineblog.com/articles/setup-redmine-to-send-email-using-gmail/
had similar network issues. use the code below in irb to get debug info right in the console.
require 'net/smtp'
smtp = Net::SMTP.new('ip_or_dns_address', port)
smtp.debug_output = $stdout
smtp.enable_starttls_auto#skip if not needed
smtp.start("domain", "user", "password", auth_type)
never really found out what the issue was. they moved the exchange server and the production server stopped sending emails. im not really an IT guy but there were different debug logs depending which part of the network i was on. finally "solved" the problem by sending unauthenticated email...
You could connect to the SMTP server and query the supported authentication methods:
telnet smtp.server.net 25
EHLO
The server should respond with at least one line that starts with 250-AUTH. After that the supported authentication methods are listed. Chances are that the Exchange server only supports authentication via GSSAPI or NTLM. In the latter case you might be able to get it to work with the ruby-ntlm gem and the ntlm authentication method. (See http://www.breckenedge.com/configuration-of-ruby-on-rails-actionmailer-for-microsoft-exchange-smtp)
I'm trying to send simple email via Ruby (no rails) on OS X, with XCode (which installs Ruby.) But I'm running into a problem with my smtp server which requires the email client to check mail before sending as a form of authentication.
How can I get Ruby to authenticate with the smtp server in a "POP" fashion before I can send mail? Not download mail; I only want to send html formatted email (eventually via Applescript calling Ruby, because Applescript doesn't support smtp), but the server requires that I check mail before I send.
Edit 4/05/10:
Well, that's embarrasing. Turned out to be simpler; I was trying to make it more complex than it needed to be. Even though my mail server requires pop before smtp, this sends OK:
require 'net/smtp'
message = <<MESSAGE_END
From: Private Person <me#fromdomain.com>
To: A Test User <test#todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
MESSAGE_END
Net::SMTP.start('mail.mydomain.com', 25) do |smtp|
smtp.send_message message,
'mark#mydomain.com',
'mark#mydomain.com'
end
Edit 4/04/10:
With this I get a 500 unrecognized command error; the pop server is responding, though.
require 'net/smtp'
require 'net/pop'
message = <<MESSAGE_END
From: Private Person <me#fromdomain.com>
To: A Test User <test#todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
MESSAGE_END
Net::POP3.start('mail.mydomain.com', 110, 'mark#mydomain.com', 'password') do |pop|
// If this line is included,
// I get a printout of the number
// of emails on the server
// right before the error:
//
// puts pop.n_mails end
Net::SMTP.start('mail.markratledge.com',
25,
'localhost',
'mark#mydomain.com', 'password', :plain) do |smtp|
smtp.send_message message, 'mark#mydomain.com',
'mark#mydomain.com'
end
end
POP before SMTP isn't one of the authentication types supported by Net::SMTP so I think you're going to have to use Net::POP3 to do your POP3 login e.g.
require 'net/pop'
pop = Net::POP3.start(addr, port, account, password)
pop.finish
Net::POP3 is in the Standard Library so should be available anywhere that Net::SMTP is.
If that doesn't make your server happy then Net::Telnet will let you send the raw commands yourself.
I'm trying to get a Ruby script to download a file off a server, but I'm getting a 401.2 from IIS:
You do not have permission to view
this directory or page using the
credentials that you supplied because
your Web browser is sending a
WWW-Authenticate header field that the
Web server is not configured to
accept.
I've checked that basic auth is enabled. Is there something special about how Ruby handles basic auth? Is there a way for me to see what the server actually gets and what the headers say is acceptable?
This is my code:
Net::HTTP.start(url, port) {|http|
req = Net::HTTP::Get.new('/file.txt')
req.basic_auth 'username', 'password'
response = http.request(req)
puts response.body
}
Snippet from the Microsoft website
HTTP 401.2: Denied by server configuration
Description
The client browser and IIS could not agree on an authentication protocol.
Common reasons
* No authentication protocol (including anonymous) is selected in IIS. At least one authentication type must be selected. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
253667 (http://support.microsoft.com/kb/253667/ ) Error message: HTTP 401.2 - Unauthorized: Logon failed due to server configuration with no authentication
* Only Integrated authentication is enabled, and an older, non-Internet Explorer client browser tries to access the site. This happens because the client browser cannot perform Integrated authentication. To resolve this problem, use one of the following methods:
o Configure IIS to accept Basic authentication. This should only occur over SSL for security purposes.
o Use a client browser that can perform Integrated authentication. Internet Explorer and new versions of Netscape Navigator and Mozilla Firefox can perform Integrated authentication.
* Integrated authentication is through a proxy. This happens because the proxy doesn't maintain the NTLM-authenticated connection and thus sends an anonymous request from the client to the server. Options to resolve this problem are as follows:
o Configure IIS to accept Basic authentication. This should only occur over SSL for security purposes.
o Don't use a proxy.
You should also try to look at ruby-httpclient - Simple HTTPClient library for Ruby which can use NTLM auth.