views:

155

answers:

5

Hi,

I have a C# Web App (Using ASP.NET 2.0) and I want to use it to send email. I have researched about this online, but I've only gotten more confused. I have learned some basics, but it isn't getting me anywhere. Here's what I have so far:

         MailMessage message = new MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);
        SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text);
        emailClient.Send(message);

All the controls prefixed txt are text boxes. I got part of this from an onlin tutorial, but it doesn't work because I'm not sure what I should put in the SMTP server Textbox. Can anyone help me? Thanks

+3  A: 

You need to put in your local SMTP server - probably the one in the same network as your web server. You may even be able to just use "localhost" if the IIS you're running on sends mail as well. Alternatively, are you running Exchange somewhere in the network?

Jon Skeet
Yes I am running Exchange
zohair
Also, when I try 'localhost' it gives me this error: 'An established connection was aborted by the software in your host machine '
zohair
@zohair: That would suggest you're not running an SMTP server on localhost then.
Jon Skeet
Is it possible to use this to set up to use Exchange?
awe
What can I do to overcome this problem then?
zohair
You find out where your Exchange server is and then send to that... having made sure it has SMTP enabled.
Jon Skeet
+1  A: 

This refers to the address of the SMTP server (the outgoing mail) that will process the message. If you have Outlook or Thunderbird installed, open up your email account settings and take a look in their for your SMTP details.

Pete OHanlon
A: 

Check System.Net.Mail and System.Web.Mail

You will find there everything about sending emails using .Net

Amr ElGarhy
+1  A: 

put this in your web.config, SMTP outgoing server setting

<system.net>
 <mailSettings>
  <smtp deliveryMethod="Network">
   <network defaultCredentials="false" port="25" host="mail.abc.com" userName="[email protected]" password="abc123"/>
  </smtp>
 </mailSettings>
</system.net>

and make an object of an smtp like, it will take SMTP setting automatically

    SmtpClient emailClient = new SmtpClient();

check this thread as well.http://stackoverflow.com/questions/1426343/sending-email-in-asp-net-2-0

Muhammad Akhtar
+1  A: 

It depends on where you run your project. If it is your localhost, just put localhost or you wanna publish it on a hosted web site, you should put the mail server name that is given by the company or write local host again. I think it works. For port number you may use 25.

  • If you use it on your localhost (intranet) use a mail server program that establishes a mail server to your personal computer. Eg. EasyMail
blgnklc