Relay SMTP RRS feed

  • Question

  • User-94285869 posted


    I'm using Windows Server 2008 R2 and IIS 7.0.

    I have a web application that we are hosting in our own web server.  I am unable to setup the web server as an SMTP server.  As a workaround, we're forwarding emails received via a web form to another server that has SMTP role.  I can't get it to do that.  Here's my code snippet which is in a Comments web page.  When the user clicks the send button this should fire up:

    using(MailMessage message = new MailMessage())
        message.From = new MailAddress(tboxEmail.Text);

        SmtpClient client = new SmtpClient("server-relay-domain-address-here", 465);
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.EnableSsl = true
        client.UseDefaultCredentials = false;

    My IIS settings for SMTP E-mail is:

    Deliver email to SMTP Server:  servername here...
    Port:  say, 465
    Specify credentials:  username/password specified


    When I run this in debug mode, it just never makes a connection and just times out.

    Does anyone know how to setup a web server to forward email to a "relay" server?

    Tuesday, August 20, 2013 6:13 PM

All replies

  • User-760709272 posted
    SmtpClient client = new SmtpClient("server-relay-domain-address-here", 25);

    The port is the port the smtp server you are connecting to is running on (chances are it is 25), nothing to do with your local iis settings as you are going direct to that remote server and the remote server is doing the relay.  You aren't telling your local iis smtp to send to that server.  If that doesn't work try without credentials etc too.  Failing that, ask the person who owns the server what settings you need to send through it.

    Edit: If you *do* actually want to relay through your local iis then the smtp server for your SmtpClient is "localhost", "" or however you refer to the local machine.

    Tuesday, August 20, 2013 6:29 PM
  • User1173053962 posted

    It seems you are not specifying the credentials on SmtpClient.

    Here's an example:

    using System.Net.Mail
    MailMessage msgMail = new MailMessage();
    MailMessage myMessage = new MailMessage();
    myMessage.From = new MailAddress("sender's email","sender`s name");
    myMessage.To.Add("recipient's email");
    myMessage.Subject = "Subject";
    myMessage.IsBodyHtml = true;
    myMessage.Body = "Message Body";
    SmtpClient mySmtpClient = new SmtpClient();
    System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("username", "password");
    mySmtpClient.Host = "your smtp host address";
    mySmtpClient.UseDefaultCredentials = false;
    mySmtpClient.Credentials = myCredential;
    mySmtpClient.ServicePoint.MaxIdleTime = 1;

    Also try to telnet to the smtp server on port 25 from your server so you can test the conectivity.

    If telnet fails check firewalls on both servers. Maybe there are some kind of blocking configured.

    Hope this will help.

    Tuesday, August 20, 2013 6:30 PM
  • User-94285869 posted


    Been swamped with other stuff.  Sorry for delay in responding.

    Still not able to resolve this.  We are able to connect to the remote server; my IT guy tested it by sending an email to the remote server via Outlook.  We can't test by ping or telnet since the remote server blocks those.

    We still don't know why my web page is not able to connect to the remote server.  I followed the specs you specified above.  Don't see any conflict in our web server.  But it still doesn't work.  I get this error,

    "No connection could be made because the target machine actively refused it. (SocketException (0x274d).


    Thursday, September 5, 2013 12:38 PM
  • User-760709272 posted

    Did he try sending through outlook via that smtp server, using Outlook on the webserver itself?  If not then it's not a proper test of the web server's ability to send via that smtp.  It could be that the smtp server isn't allowing connections from your webserve via firewall settings or something.  If you can't telnet or ping then download a port scanning tool and run it from the webserver to see if port 25 is open.

    Thursday, September 5, 2013 6:02 PM
  • User-94285869 posted

    Yes.  He configured the web server's Outlook and sent the email from the web server itself.  Port 25 on our web server is open.  Remember though, that our web server is no longer acting as an SMTP; we had to turn off that server role because we're no longer allowed to configure our web server as an SMTP (company policy).  That's why we have to relay it to the remote server that is allowed to act as SMTP.


    Thanks for replying.


    Friday, September 6, 2013 5:16 AM
  • User-760709272 posted

    Can you not just use the proper smtp server direct from your webserver rather than relaying through the local smtp on the web server?

    Friday, September 6, 2013 6:02 AM
  • User-94285869 posted

    We'd like to but we are NOT allowed by company policy.  They had a big re-organization and security updates and stuff and we're told we cannot use this web server as an SMTP, period.

    Friday, September 6, 2013 10:23 AM
  • User-760709272 posted

    I'm not suggesting you do, I thought from your description you were sending via the local webserver's smtp which was relaying to your proper smtp.  I don't see how you can connect to the smtp server via outout but not your code.  There is no difference.  I suspect that your network people didn't really do a proper test.  If Outlook running on the webserver can connect to the smtp server and send mail through it, so should your code.

    Friday, September 6, 2013 10:33 AM
  • User-801004448 posted


    We can't test by ping or telnet since the remote server blocks those.

    Telnet port 465 creates same type of connection Outlook connect to relay mail server to send email.

    I assume that outlook on your web server is also configured to connect to relay mail server on smtp port 465.

    Thursday, September 19, 2013 4:07 AM