ASP.NET & Exchange

PHTech

Senior Member
Joined
Aug 21, 2006
Messages
588
Reaction score
0
Location
Witbank
Hi there...

I need to compile a webpage which will need to send an e-mail when the form is submitted...

I am using asp.net for it, and when sending the e-mail, it should use the Microsoft Exchange system... How do I implement that in a form, or just configure the ASP.NET code so that it will use our Exchange to send mail to a mail group, or specific mailbox...

Thanx...
 
Will this be the right way to do it...?

Code:
Dim mail As New MailMessage() 
mail.From = [email protected] 
mail.To = [email protected] 
mail.Subject = "Subject" 
mail.Body = "This is a test message" 
SmtpMail.SmtpServer = "10.1.0.1" 'this is the IP of the exchange server 
SmtpMail.Send(mail)
 
Hey PHTek

Here is a video tutorial from the official ASP.Net website that runs you through the whole process. (I think you need to have Silverlight installed, but try anyway).

It appears to me that you are using the System.Web.Mail nampespace and the following classes: System.Web.Mail.MailMessage, System.Web.Mail.SmtpMail.

Note that this namespace and its classes have been deprecated.

You should use the System.Net.Mail namespace, as used in the video.

As far as I know, MS Exchange is not an SMTP server, and you have to use an SMTP server to send email, or drop the emails inside a pick-up directory which the SMTP server (or possibly MS Exchange) will read from.

If you google it, you'll find the right answer.
 
You can use Exchange as an SMTP server, our one here at the office is set up like that. I can telnet into port 25 (or is it 100?) and send a mail from putty, not that I would ever want to - but it can be done.

How the "insides" work, I'm not so sure, but from the outside it behaves like a normal SMTP server...

I stand corrected.

PHTek.. you should then just specify the IP Address or hostname of your SMTP server, and port number if it is different from the default, and then send it.

SmtpClient client = new SmtpClient(192.168.0.22);
client.Send(mailMessage);

Let me know if you are able to send emails using your Exchange server, and through which port. I'm interested to know because at my previous job some of the guys working on another project struggled to get an SMTP server working with Exchange. We DID have a couple of dimwits working for us.. that could be the reason they couldn't get it..
 
Last edited:
You'd need to use authentication in case you require user/pass for sending mail through the Exchange.

I assume this is on an intranet... otherwise you're in for some abuse re: the open smtp server
 
I have been sending email via Exchange using the new SmtpClient("196.168.0.22").Send(mailMessage) for some time now. It works flawless.

The one thing you have be on the lookout for though is how your Exchange server is setup. If it is setup so that you need to authenticate then you would need to pass credentials to the SmtpClient by doing the following:

client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential("username", "password", "domain");

That should work. If it doesn't then your mail admins must go back to school on setting up exchange...
 
I have been sending email via Exchange using the new SmtpClient("196.168.0.22").Send(mailMessage) for some time now. It works flawless.

The one thing you have be on the lookout for though is how your Exchange server is setup. If it is setup so that you need to authenticate then you would need to pass credentials to the SmtpClient by doing the following:

client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential("username", "password", "domain");

That should work. If it doesn't then your mail admins must go back to school on setting up exchange...

Stole the words right from my mouth. I'm slow to react today - I only recognized I was speechless after 5-and-a-half-hours! Yikes! :eek:
 
Precisely...

As far as any "app" is concerned.. Exchange behaves exactly like any other SMTP server.... just send the mails to it and you should be aye-for-away from there...

And yeah, if the credentials bit doesn't work..... find your admins and beat them with a wifflebat spiked with nails...
 
Top
Sign up to the MyBroadband newsletter
X