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);
....etc.
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", "127.0.0.1" or however you refer to the local machine.
I'm afraid I no longer use this forum due to the new point allocation system.
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).
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.
I'm afraid I no longer use this forum due to the new point allocation system.
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.
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.
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.
I'm afraid I no longer use this forum due to the new point allocation system.
Member
68 Points
342 Posts
Relay SMTP
Aug 20, 2013 06:13 PM|mgambone|LINK
Hi,
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);
....etc.
SmtpClient client = new SmtpClient("server-relay-domain-address-here", 465);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true
client.UseDefaultCredentials = false;
client.Send(message);
}
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?
All-Star
37441 Points
9076 Posts
Re: Relay SMTP
Aug 20, 2013 06:29 PM|AidyF|LINK
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", "127.0.0.1" or however you refer to the local machine.
Member
110 Points
38 Posts
Re: Relay SMTP
Aug 20, 2013 06:30 PM|FilipePeixinho|LINK
It seems you are not specifying the credentials on SmtpClient.
Here's an example:
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.
Please Mark as Answer if the post helps you in resolving your issue !!!
Member
68 Points
342 Posts
Re: Relay SMTP
Sep 05, 2013 12:38 PM|mgambone|LINK
Hi,
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).
All-Star
37441 Points
9076 Posts
Re: Relay SMTP
Sep 05, 2013 06:02 PM|AidyF|LINK
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.
Member
68 Points
342 Posts
Re: Relay SMTP
Sep 06, 2013 05:16 AM|mgambone|LINK
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.
All-Star
37441 Points
9076 Posts
Re: Relay SMTP
Sep 06, 2013 06:02 AM|AidyF|LINK
Can you not just use the proper smtp server direct from your webserver rather than relaying through the local smtp on the web server?
Member
68 Points
342 Posts
Re: Relay SMTP
Sep 06, 2013 10:23 AM|mgambone|LINK
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.
All-Star
37441 Points
9076 Posts
Re: Relay SMTP
Sep 06, 2013 10:33 AM|AidyF|LINK
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.
Contributor
3390 Points
1079 Posts
Re: Relay SMTP
Sep 19, 2013 04:07 AM|kctt|LINK
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.