Mail can't be send: Relay access denied - ruby

I have two ruby on rails application on different servers. Both are working fine, but one (server 2) can't send any mails.
I got always the 554 5.7.1 : Relay access denied error.
On server 2 I tested the mail communication with the help of telnet and it works, but it doesn't works with the ruby on rails application.
Other application can send mails, too.
The only difference between both systems are the os (Debian 6 (server 1) and RHEL 6 (server 2)) and the ip ranges (10 network (server 2) and 53 network (server 1)).
I think the best way is to use a simple mail application, but I don't know, how to write something like that.
Thanks for any help.

The IP address of your second server is not in the whitelist for that email server, but the first one is.
Unless you're using authenticated SMTP, you will have to add the IP addresses of all your application servers to the whitelist configuration.
Using telnet will only tell you if the port is accepting connections, not if you can actually send email. For that you'll have to perform an actual SMTP transaction.
There are services like Postmark, SendGrid or even my start-up PostageApp which will act as a mail server for you.

Related

SMTP Emails Sending out Intermittently from application

I'm facing kind of SMTP mail problem sending through the application using coding as below
SmtpClient SMTPServer = new SmtpClient("smtp.office365.com");
SMTPServer.UseDefaultCredentials = false;
SMTPServer.Credentials = new System.Net.NetworkCredential("xxx#xxx.org","xxxxx")
SMTPServer.Port = 587;
SMTPServer.EnableSsl = true;
So been using this method 2 years ago until recently where we face email not able to send out intermittently with error message "Smtp Error: Failure sending mail". There are times where emails could send out with only average 12 emails per day. Plus, the sender email address from the application is active with correct credential login and password.
I checked our Windows 2008 R2 server and tested with our disabled firewall on server. Problem still persists. And there were no patches update to the server as well.
Is there anything to do with authentication type level? Or certain communication protocol conflicts? How do I check further to determine the root of cause? Our firewall already allowed the port 587 to send out.
There could be many issues to check. You say that the application is sending emails as a "client" to an Exchange 365 SMTP server to sent onwards, that's what the example looks like.
Check that Exchange is not rejecting the request. Microsoft can be very picky about application clients connecting directly. Look in the logs.
Check that your email application client uses TLS 1.2 or above. Many SMTP servers will reject requests below that level.
Exchange might be insisting on a STARTTLS for negotiation on credentials, so check if that is the issue.
Check that the application client is whitelisted in MS Exchange 365 if it is rejecting requests.
Check that the user you are connecting as has privilege to accept connections from remote clients. I often lock this down to prevent brute force password attacks.
Normally I would test all this out on the command line first. Get an email client for your OS like:
sendemail-1.56 by Brandon Zehm <caspian#dotconf.net>
Which is very good at initiating a connection to a remote server. Test from your application client email server and see what happens.

Issues setting up SMTP server

I have read numerous articles and done everything recommended to setup a mail server in windows 2008R2
I am simply trying to send messages from my server from certain websites that I host.
I queued mail for delivery then got this back....
4.4.7 Unable to deliver message to the following recipients, due to being unable to connect successfully to the destination mail server.
For reference, I followed the instructions here...
How to setup an SMTP server
Is there something I am missing?
While I am not familiar with Windows mail servers, I have encountered a similar issue. If this only happens with some destinations, the receiving mail server could be simply refusing the connection.
For example, mail servers often refuse connections from IP addresses that ISPs hand out to "regular" (non-business) customers. Another common reason to reject mail is if the reverse DNS entry for your IP doesn't match the hostname in the HELO (or EHLO) command. (However, in that case, you probably wouldn't get "unable to connect" errors.)
You could try online tools like mxtoolbox to help diagnose the problem.

How to test smtp email with DOS, not telnet?

I know how to test smtp email using telnet. But I think because telnet uses "its own channel" to reach smtp server, it doesn't necessarily mean the normal smtp communication on port 25 would work. (Please correct me if this is not true)
Basically the client has encountered with an issue : [ERROR] Access to default session denied during a test from application to reach smtp server. From the same server, telnet to send an email just works...
So I've got no other choice but to figure out why I am getting this sort of error. Done my research only to find out lots and lots of command-line email applications, no good in this case as it is the client's environment that I've got little control on what to install.
So I think the last resort would be using simple DOS commands? Please advise if there is even a better way. Many thanks in advance.
I know how to test smtp email using telnet. But I think because telnet uses "its own channel" to reach smtp server, it doesn't necessarily mean the normal smtp communication on port 25 would work.
That's incorrect. If sending e-mail works with typing it to the Windows telnet application, then it works, i.e. there is no problem with the SMTP server, and there are no firewall issues between the client and the server.
So the bug is most probably in the in the application displaying the error message. Maybe there is no bug, but the application is not configured properly.
I think because telnet uses "its own channel" to reach smtp server, it doesn't necessarily mean the normal smtp communication on port 25 would work. (Please correct me if this is not true)
That is not true. A "real" SMTP client uses the same method to talk to the SMTP server as telnet does.
If you do not trust Telnet, use Thunderbird, but the problem is probably with your client software or configuration. Double check the settings there and see if you can turn on any trace logging (on the client or the server).

Ruby ultra simplistic mail server

I am trying to create a simple ruby mail server ( SMTP server) just or fun. I tried the code in the http://snippets.dzone.com/posts/show/3932
I am not able to sendmail from my machine. I also posted comment there but no reply ;(.
Can any you please help me by giving a pointer or a simple ruby smtp server that can send mail to my gmail account without using a SMTP servers or MTA.
Your SMTP server still needs to connect to smtp.gmail.com to forward your mail. The protocol for doing so can be found in RFC821 (http://james.apache.org/server/rfclist/smtp/rfc0821.txt)
It looks like the example above just allows you to connect to the SMTP server on localhost and store mails locally.

trouble sending mail with free smtp

I am trying to send mail from a local iis app using localhost as my smtp server after installing free smtp but I am getting the following error:
Mailbox unavailable. The server response was: Invalid
recipient: 'validAddress'#hotmail.com
Any idea what the problem could be?
it sounds like your free (3rd party) smtp app is not leaving your network and might be trying to see if it has that mailbox itself. Try and see if there is a setting to allow the smtp server to access external connections, etc. What is the name of the free smtp app, btw?
Alternatively, can u use the built in SMTP mail provider, built into iis? do you know how to use that, instead of this 3rd party app.
It looks more like the SMTP service needs to be configured to "Relay" email... Usually this involves telling it what YOUR mail domain is, and then any mail destin for a domain other than it's own will cause it to go out to the world, and try to relay the message to the real server.
But, be careful! This is how spammers exploit email servers. They look for SMTP listeners that will relay for them. You want to make sure yours will only accept relay mail from "localhost", or whatever machine will be connecting to it to do the sending.
A more secure way is to block port 25 inbound at your firewall to this box, so this SMTP server is not visible to the outside world.
Write and test a simple smtp sender in C. It needs 3 minutes with RFC
Use Wireshark to see what comes on the wire between your application and the SMTP server.

Resources