Syntax error, command unrecognized. The server response was '' - c#

I've looked at 3 or 4 questions here so far and they haven't helped yet.
I have set up SmarterMail 14.x on a client's machine. I know very little about setting up mail servers (I don't know why he thinks I do) but I have it installed, a domain set up pointing to the MX record, the port open (9998) and I am able to send email just fine from the web interface.
However, I can't send email from Sql or from C#. I created a quick and dirty app to allow me to enter the server, port, credentials, and to/from and I get this response every time:
[Inner Exception]
Unable to connect to the remote server
[Details]
System.Net.Mail.SmtpException: Failure sending mail. ---> > System.Net.WebException: Unable to connect to the remote server ---> > System.Net.Sockets.SocketException: No connection could be made because the > target machine actively refused it 204.12.49.188:25
I've tried multiple logins. I've also confirmed that SMTP is turned on and IMAP/POP3 is turned off. I'd post images of it but unfortunately I can't yet.
The code to send is below and it is about as simple as it gets:
SmtpClient client = new SmtpClient(ServerTextBox.Text, Convert.ToInt32(PortTextBox.Text));
NetworkCredential login = new NetworkCredential(UsernameTextBox.Text, PasswordTextBox.Text);
client.Credentials = login;
MailMessage message = new MailMessage(FromTextBox.Text, ToTextBox.Text, "Wine and Spirits Jobs Alerts", "Below are this week's job alerts: There are no job alerts at this time");
client.SendCompleted += HandleSendCompleted;
client.SendAsync(message, null);
I've also tried it locally on their VPS and on my machine. I've turned on and off the firewall and I've got a specific rule allowing outgoing traffic on 9998 (and you can log into the web interface remotely) so this isn't a matter of being able to contact it.
I'm at a loss of what to do. If someone can help??
EDIT: It's clear I was using the wrong port - 9998 instead of 25. Using port 25 now tells me either time out or that it was actively refused. The firewall does have specific rules for port 25 that allow all traffic, so it shouldn't be stopped.
EDIT 2: I've re-created the MX record on the domain and ensured it is pointing to the correct IP address. I've also re-created the domain in Smartermail and made sure SMTP is turned on, authentication is required, SSL is not, POP and IMAP are turned off, and that my login is correct. I've also tried turning on and off the firewall. No dice.

I finally solved the issue.
It had nothing to do with firewalls or the MX record or using/not using an IP address and everything to do with the fact that while port 25 was indeed assigned to SMTP and SMTP was indeed turned on, the IP address of the domain itself was NOT assigned to the SMTP configuration so SmarterMail wasn't actually monitoring the port.
Problem solved - email sends. Fun stuff! Thank you for everyone's responses!

Try setting SMTP mail server IP address in your mail sending code.
SmtpMail.SmtpServer = "your mail server name or IP address goes here";
SmtpMail.Send(Message);
Your can set this property at global level or in any Initialization code.
Reference : https://msdn.microsoft.com/en-us/library/system.web.mail.smtpmail%28v=vs.110%29.aspx

Related

Validating TLS email reception

I am trying to convert our current email agent to send email with TLS. We use C# and I just used the following changes.
SmtpClient sclient = new SmtpClient();
sclient.EnableSsl = true;
and a callback method to validate server certificate.
On Testing the mail was sent/received successully, but both I and the receiving end cannot be 100% sure the the email was received encrypted. (I tried to use Fiddler but its not capturing the email)
Based on this http://luxsci.com/blog/how-you-can-tell-if-an-email-was-sent-using-tls-encryption.html, and the header as below
with ESMTP id s7JKErN9002462
(version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO);
Can we safely assume that the mail communication indeed was encrypted? or Should I make any other code changes so that I can be sure that the email is received or it failed? (I think this cannot be certain as it depends on the smtp host) ?
In the end you can always check the TLS connection using network sniffer software such as WireShark.
Of course if you only leave a connection open to the SSL port of the server, and you receive the server certificate, you can be pretty certain the mail did not appear from the blue sky anyway.
You can safely assume that if you are able to connect and send, that the tunnel you're delivering the mail to is secure.
The SmtpClient code is solid and you can trust it. If it fails to connect securely after you've asked it to, it throws an exception, so you'll know something is not like you were expecting.

SMTPException : Unable to read data from the transport connection: net_io_connectionclosed

I know that this question looks like duplicate of dozens other questions while its not.
When ever i try to send an email on my local machine through my web application an SMTPException is thrown and the exceptions is :
//on this line : SmtpServer.Send(mail);
Unable to read data from the transport connection: net_io_connectionclosed.
While the code on production is working perfectly, the same code, the same connections, the same credentials, i'm using IP instead of alias, i tried to turn off the firewall on my local machine, and nothing helped me to fix this issue.
While on my local machine is used to work previously, can anyone give just a hint what could be the problem that raising this issue?
If you are on a residential internet connection, quite often your ISP will block outgoing email sends by blocking all outbound connections to port 25. This is quite common here in the US. Try connecting to a local email server over TCP/IP, or to one on your own internal network.
This thread contains some.
For instance: it looks like assigning a static IP might solve the problem.
What this error means is that System.net.mail was unable to find the
smtp server.
The answer will vary depending on whether you have a fixed IP or a
dynamic IP but, basically, you need to assign a valid IP to your smtp
server.
With fixed IP's this is relatively straightforward. With dynamic IP's
it takes a bit of tweaking.
Open the IIS Manager and check the properties for the smtp server.
In the Default SMTP Virtual Server's properties, in the "Access" tab,
in the Connection Control and Relay dialogs, make sure that your local
IP is assigned. ( In my case, it's 10.0.0.2... )
You may also need to modify your hosts file, to point 127.0.0.1 to
your machine name. ( \WINDOWS\system32\drivers\etc\hosts )
Then, in your code, assign your machine name to the smtp client :
Dim client As New SmtpClient("yourmachinename") client.Send(mail)
Alternatively another guy in the same thread seems to have found a workaround for the SMTP connection not being correctly closed.
Set SmtpClient.ServicePoint.MaxIdleTime = 1 according to a supported
work-around:
http://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?FeedbackID=146711
which makes all smtp work properly.
Here's a complete sample:
MailMessage msgMail = new MailMessage();
msgMail.To.Add(new MailAddress("info#somedomain.se"));
msgMail.Subject = "Message from web";
msgMail.IsBodyHtml = true;
msgMail.Body = "Test message";
SmtpClient Client = new SmtpClient(); /* uses settings form web.config */
Client.ServicePoint.MaxIdleTime = 1; /* without this the connection is idle too long and not terminated, times out at the server and gives sequencing errors */
Client.Send(msgMail);
msgMail.Dispose();
System.Net.NetworkCredential(user, password); ///Wrong
System.Net.NetworkCredential(email, password); ///right
because some email server is shability
In my case, I had to leave out the Domain property from Network Credentials when setting username and password
The Gmail account you are using has limit for number of emails being sent out per day/month and if you exceed that limit, it will reject any further outgoing emails.

WebMatrix Not sending mail now that it is moved to the server

I am trying to get WebMatrix running on a local server (simply for testing within our intranet), but it is having trouble sending mail where it never did before on my local (work) machine.
I am getting a simple, the operation has timed out message. The account for this is setup through gmail, so I wouldn't think that there would be too many problems, but as I have never set up WebMatrix on a server before, I don't really know how to attack this issue.
When I had the Email working in construction of this website, I used these settings and everything worked fine:
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
Then when I ran it with these settings on the server I got this error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first.
With that, we tried to enable SSL, but get a simple response timed out request after that (using these settings):
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 465;
WebMail.EnableSsl = true;
The "Username" and "From" fields are set the same (name#somecity.net) this is an example of our email that is managed by gmail. Also the password is set and correct.
Am I chasing the wrong thing here, by looking into SSL?
You'll have to forgive me in that I have never implemented SSL before. I know what SSL is, but I have never set it up before, so I apologize if I am a kind of a noob when it comes to setting this up.
Also, just so you know for sure, the server error does, in fact, error on the WebMail.Send method.
You should change your SMTP port for the Gmail one. Right now, gmail is working with 587 instead of 465.
You can check it using telnet smtp.gmail.com 587. Then you should get something like this:
220 test.auto.mySMTPserver.com ESMTP Service (Lotus Domino Release 8.5.3FP2 HF95) ready at Tue, 30 Oct 2012 08:27:31 -0700
Your new code:
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 587;
WebMail.EnableSsl = true;
And that's it.
I would say that the message tells you you are not authenticated, so you are likely to need to send a username / password for a valid user on the server. See this question for an example of authenticating to a mail server to send.

How to send email through IIS7?

I'm trying to set up a SMTP server on my Windows 7 machine in IIS7. I have set it to "Deliver email to localhost, port 25, no authentication. But when I try to connect programmatically from my C# program, I get an error:
Failure sending mail", inner exception "No connection could be made because the target machine actively refused it 127.0.0.1:25
public static void SendEmail(MailMessage m) {
var smtp = new SmtpClient {
Host = "localhost",
Port = 25,
UseDefaultCredentials = true,
};
smtp.Send(m);
}
Why? What other secret switch do I have to flip?
For development purposes I use storing mails to filesystem, try this in the web.config
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\temp\mails\" />
</smtp>
</mailSettings>
Sorry, but most of these answers were totally confusing and don't explain the problem . Here is what the problem is.
The "SMTP E-mail" in IIS 7, on both Windows 7 Professional and "real" web server like Windows Server 2008 is that SMTP E-mail is not a true "virtual SMTP server" or what Microsoft calls "Simple Mail Transfer Protocol (SMTP)". Its just a an interface that allows you to apps that to an SMTP server online. The virtual SMTP server we used to have on older Windows is now only available as an add-on on server operating systems using the "Server Manager" under Administrative Tools and clicking "add features". Thats not found on say Windows 7 Professional. Yet another Microsoft blunder!
However, you can still use the "SMTP E-mail" piece under IIs in development or even your Web Server to route mail out to a real SMTP server. Its not like the old days when both were one and the same and you could route email out and back to your local box, etc for testing. They let you store that locally but thats not much help to me. Thats why when in SMTP E-mail "localhost" doesn't work. Thats what most people are saying. For that you would need to install third party software. A better solution is to just get the Windows Server Admin pack which has the virtual server and all the web server goodies found on the server OS and install that: http://www.sysprobs.com/install-admin-pack-windows-7-remote-desktop-manager
Keep in mind, you don't have to run ANY real SMTP virtual server on either your local box or on the server as long as you have an address to a real SMTP service (like "mail.yourwebhost.com"). Under IIS7, just click your SMTP E-mail piece under IIS7 and type in the address. But "localhost" wont wor'k. Usng SMTP E-mail with a remote host, I've found most SMTP or email providers require two additional things: a port other than "25", and you adding custom authentication credentials found under SMTP E-mail. Network Solutions likes to use your email address for the login and your address password. I hooked all that up and the mail c# object sent out mail without a virtual SMTP server on my local box. Last trick is be sure to also add this to your c# code:
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(
"mail.yourhost.com",155);//add custom port here
//This object stores the authentication values
System.Net.NetworkCredential mycredentials = new System.Net.NetworkCredential(
"yourname#yourdomain.com", "passwordhere");
client.UseDefaultCredentials = false;
client.Credentials = mycredentials;
Best method I found was to use SMTP4Dev, which listens for emails, and shows you what was "sent", but doesn't actually send anything. Great for testing!
You need to setup SMTP server in IIS7, here are the instructions how to setup:
http://learn.iis.net/page.aspx/751/configure-smtp-e-mail-in-iis-7/

SMTP Email: Mailbox unavailable. The server response was: No such recipient

I created a new email box for general support questions. When I try to send an email through SMTP I receive the following error:
Mailbox unavailable. The server response was: No such recipient
I am able to email the box through Outlook and SMTP works when I send to other email address in the same domain.
The great thing about SMTP is that it's easy to spoof the conversation. The terrible thing about SMTP is also that it's easy to spoof the conversation. What makes this great is that if you want to figure out what's going wrong in a SMTP connection you can just "telnet mailhost 25" and start issuing SMTP commands like:
HELO example.com
MAIL FROM: <me#me.com>
RCPT TO: <him#him.com>
DATA
Subject: test message
From: Me <me#me.com>
To: Him <him#him.com>
test message
.
QUIT
Is your DNS configured properly? You need an MX record specifying which host handles incoming messages for that domain.
Btw, your post is missing some details, like which server you are using etc. That makes it hard to find where the problem is.
If you post the complete SMTP conversation (or at least what your client is sending) the answer will probably leap out at you.
Or, if you're speaking SMTP correctly, perhaps you're connecting to the wrong server. Does your client look up the DNS MX record to find the right SMTP host?
First, make sure the address is valid. Also, make sure the From address is valid (that may be your problem). Finally if those do not work, you should try setting the SMTP server explicitly.
Without a bit of a code sample, that's the best advice that I can come up with.
Does your company have multiple mail servers? No such recipient might be returned if you have multiple servers and the newly created account hasn't been pushed through yet.
I actually used Telnet to diagnose the problem (Thanks to Paul Tomblin for his post). I found out that our SMTP server uses GroupWise (we use Exchange as our main email client). I had to set up the address to relay to the GroupWise server as well.

Categories

Resources