3

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.

  • It sounds like an error on the server side. If you can, I'd install a TCP sniffer and see what the SMTP traffic looks like. Maybe we can pinpoint the error. If you can't use a sniffer, http://blogs.msdn.com/b/dgorti/archive/2005/09/18/471003.aspx will describe how you can turn on tracing which might help. – dmeglio Jul 31 '15 at 16:34
  • Okay, I tried that. I get: 'Bad Request' –  Jul 31 '15 at 17:17
  • Umm that's HTTP traffic and you're getting back HTML... I don't think you're talking to an SMTP server. Cassini is the web server built into Visual Studio. Are you sure 9998 is the correct port? SMTP is usually 25. – dmeglio Jul 31 '15 at 18:14
  • Yeah that's what's odd. 9998 is the only way to get into the web mail interface. When I try port 25 I get "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" Port 25 has special firewall rules to allow inbound and outbound connections. Rules are not disabled and it is not blocked. –  Jul 31 '15 at 19:05
  • Web mail won't work in an SmtpClient. Web mail uses HTTP. You need SMTP access. Web mail is not going to work for you. – dmeglio Jul 31 '15 at 19:38
  • I understand that, dman. I mean that the web interface is accessible through 9998. I've already confirmed that I've turned SMTP on for that domain in SmarterMail (professional edition) and turned off IMAP and Pop3. SMTP is accessible for mail.wineandspiritsjobs.com. Looks like it's on port 25, but now port 25 says either timeout or refused. –  Jul 31 '15 at 19:44
  • Yeah, if 9998 is web mail, then it can't also be SMTP so it will be on another port. It is probably on port 25 because that's the default. If you're getting a time out or refused, then it sounds like a firewall issue (either hardware or Windows). – dmeglio Jul 31 '15 at 19:58

2 Answers2

3

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!

1

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

Roshan
  • 31
  • 3
  • When I use the IP I get refused. When I use the name, I get "System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The operation has timed out. at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result) at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)" –  Jul 31 '15 at 19:12
  • If you IP is getting refused that means it is not registered to send mail to that Particular Mailing server (i.e. to that IP address). Check with the Mail Server (Admin team) whether it accepts the request from your server (your server IP address). – Roshan Aug 01 '15 at 07:47
  • I'm not sure what you mean. We set up SmarterMail Professional on the VPS. Domain's MX record points to the IP address. I can send mail through their web interface. I just can't send mail via SMTP from that server, with or without the firewall. –  Aug 01 '15 at 22:11