What am I doing wrong? System.Net.Mail

J

justsome_newbie

Hello experts! I'm trying to send mail from my C# Asp.Net webpage. I
used the code samples at www.systemnetmail.com but it still won't send.
I think the problem is on the iis or exchange server side but I can't
find any tutorials on how to configure the server(s). Any good links
for this?

Any advice is welcome!
 
M

Mark Rae

but it still won't send.

That really doesn't tell us much...
I think the problem is on the iis or exchange server side

What makes you think that...?
but I can't find any tutorials on how to configure the server(s).

Er, well can your webserver see the Exchange server? What account are you
using? Does it require authentication?
Any good links for this?
http://www.systemnetmail.com

Any advice is welcome!

You could start by showing us your code...
 
J

justsome_newbie

Sorry, it's my first post, I didn't know what all you needed. I'll try
to answer you're questions better this time.

This is what I was using, I actually took the the sample directly from
the "How do I send a simple Html email?" section (changing the email
addresses and host name). I tried using both the IP address and the
actual name of the exchange server but neither worked.
What makes you think that...?

I figured that since I used the code on the systemnetmail.com page that
the code was fine, meaning the problem must be with iis or exchange. I
could easily be wrong though, I've never used the System.Net.Mail
classes and have no iis/exchange experience (this is my first asp.net
project)
Er, well can your webserver see the Exchange server? What account are you
using? Does it require authentication?

How do I check if my webserver can see the Exchange server? Our network
admin said that no authenication is required, but I still tried using
"smtp.Credentials = new NetworkCredential("userid", "password");" with
a valid username and password and it still failed.
That really doesn't tell us much...

It throws a System.Net.Mail.SmtpException with message "Failure to send
mail" with an inner exeption System.Web.MailException with message
"Unable to connect to the remote server"

Thanks for you help so far! Hopefully this post is clearer than my last
one.

Thanks Again!
 
M

Mark Rae

Sorry, it's my first post, I didn't know what all you needed. I'll try
to answer you're questions better this time.

That's OK. For the future, the following would really help us to help you
i.e. you'd probably get an anwer much more quickly...:)

1) Make the subject of your post descriptive

2) Briefly mention the software you're using - that's especially important
if you're not using the latest versions, because we'll assume you are unless
you say you're not.

3) Explain what you're trying to do

4) Describe how you've tried to do it

5) If you're getting errors, tell us what they are - the more information,
the better.

6) Provide as much of the code as is relevant - especially the bits where
the error occurs... :)
This is what I was using, I actually took the the sample directly from
the "How do I send a simple Html email?" section (changing the email
addresses and host name). I tried using both the IP address and the
actual name of the exchange server but neither worked.
OK.

I figured that since I used the code on the systemnetmail.com page that
the code was fine, meaning the problem must be with iis or exchange. I
could easily be wrong though, I've never used the System.Net.Mail
classes and have no iis/exchange experience (this is my first asp.net
project)

From what you've said, I doubt very much that there is a problem with your
Exchange server - if there was, your network admin would already know about
it.
How do I check if my webserver can see the Exchange server?

Well, first things first. Log on to the webserver and try to ping the
Exchange server. I'm assuming (because you have not said the contrary) they
both servers are on the same network.
Our network admin said that no authenication is required, but I still
tried using
"smtp.Credentials = new NetworkCredential("userid", "password");" with
a valid username and password and it still failed.

Hmm - OK...
It throws a System.Net.Mail.SmtpException with message "Failure to send
mail" with an inner exeption System.Web.MailException with message
"Unable to connect to the remote server"

Ah! Now we're getting somewhere... :) That message doesn't *necessarily*
indicate that the webserver can't actually connect to the remote server (but
do the ping test just to be sure), but certainly does indicate that
*something* is getting in the way of the mail process.

Are you using McAfee Anti-Virus software...?
 
J

justsome_newbie

Thanks again for your time, here's some more answers!
Well, first things first. Log on to the webserver and try to ping the
Exchange server. I'm assuming (because you have not said the contrary) they
both servers are on the same network.

Unfortunately, I've already left work so I'll have to wait to try
pinging the exchange server. And you are correct, they both are on the
same network. If it helps the website communicates fine with our SQL
server so I know some things are going through fine.
Are you using McAfee Anti-Virus software...?

Yep, we sure are (boy you're smart). Are their issues with McAfee and
System.Net.Mail? If it helps I did ask our Net Admin if there were any
firewalls that might be blocking the mail. He said that there wasn't
any that would block communications on the inside. (its an intranet
only app)

Also, I was wondering, is the smtp host supposed to be the exchange
server or the web server? I read somewhere that iis is supposed to
relay the email message - does that mean that the web server's iis is
supposed to send the email to the exchange server? Again, sorry if I'm
completely wrong here, I'm really lost when it comes to iis and
exchange.

Thanks again for all your help!
 
M

Mark Rae

Unfortunately, I've already left work so I'll have to wait to try
pinging the exchange server. And you are correct, they both are on the
same network. If it helps the website communicates fine with our SQL
server so I know some things are going through fine.

Like I said, I'm almost certain that's not the problem, but a quick ping
test will prove it...
Yep, we sure are

Thought so.
Are their issues with McAfee and System.Net.Mail?

Yep.
http://www.google.co.uk/search?sour...LG:2006-28,GGLG:en&q="System.Net.Mail"+McAfee
If it helps I did ask our Net Admin if there were any firewalls that
might be blocking the mail. He said that there wasn't any that would
block communications on the inside. (its an intranet only app)

McAfee is the problem, not your firewall. Its access protection is
preventing your webserver communicating out on port 25. Do the following on
your webserver:

1) right click on Virus Scan and go to the Virus scan console
2) click on Access Protection, Properties
3) in Port Blocking select Prevent mass mailing worms from sending email,
and click Edit
4) in Excluded Processes add the exe file which is trying to send the
email - for ASP.NET, it's w3wp.exe
5) save out of the dialog

If your McAfee is centrally managed using ePolicy Orchestrator, you'll need
to set it in there too, otherwise it will just overwrite your webserver's
settings.
Also, I was wondering, is the smtp host supposed to be the exchange
server or the web server?

Depends whether you want to use your Exchange server to send the emails or
your webserver - if your webserver, you'll need to enable its SMTP queue.
I read somewhere that iis is supposed to relay the email message - does
that
mean that the web server's iis is supposed to send the email to the
exchange server?

No - relaying is something different.
 
J

justsome_newbie

McAfee is the problem, not your firewall. Its access protection is
preventing your webserver communicating out on port 25. Do the following on
your webserver

You are truly amazing Mark! I'm sure this is what the problem is.
Unfortunately we're shut down for the weekend for Christmas, but at
least my mind can rest now!

Merry Christmas and Thanks a ton!
 
M

Mark Rae

You are truly amazing Mark!

No - just experienced... :) The McAfee problem is one that I have
encountered with several clients, including one of my current ones, so it's
found its way into my personal knowledge base. Now it's in yours too...:)
I'm sure this is what the problem is.

It certainly *sounds* likely, and would be the first thing I would look at,
but there are several other possible causes of mail transport failure...
 
J

justsome_newbie

Mark, I just got back to work after the Christmas break and tried your
suggestions. You were 100 percent correct with your diagnosis,
everything is now working perfectly!

Thanks again for sharing your time and expertise!
 
M

Mark Rae

Mark, I just got back to work after the Christmas break and tried your
suggestions. You were 100 percent correct with your diagnosis,
everything is now working perfectly!
Hurrah!

Thanks again for sharing your time and expertise!

No problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top