1

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

zohair
  • 2,369
  • 10
  • 35
  • 41

4 Answers4

4

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
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

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="mailer@abc.com" 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.Sending Email in ASP.NET 2.0

Community
  • 1
  • 1
Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
1

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
  • 9,086
  • 2
  • 29
  • 28
1

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
Bilgin Kılıç
  • 8,707
  • 14
  • 41
  • 67