none
how to send email in asp.net to any destination eg yahoo,gmail,hotmail etc c# code

    Question

  • hi i have try many code for sending email from msdn and many sites.but still i could do so.

    some code are here...

      SmtpClient smtpClient = new SmtpClient();

            MailMessage message = new MailMessage();

     

            try

            {

                MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text);

     

                // You can specify the host name or ipaddress of your server

                // Default in IIS will be localhost 

                smtpClient.Host = "localhost";

     

                //Default port will be 25

                smtpClient.Port = 25;

     

                //From address will be given as a MailAddress Object

                message.From = fromAddress;

     

                // To address collection of MailAddress

                message.To.Add("admin1@yoursite.com");

                message.Subject = "Feedback";

     

                // CC and BCC optional

                // MailAddressCollection class is used to send the email to various users

                // You can specify Address as new MailAddress("admin1@yoursite.com")

                message.CC.Add("admin1@yoursite.com");

                message.CC.Add("admin2@yoursite.com");

     

                // You can specify Address directly as string

                message.Bcc.Add(new MailAddress("admin3@yoursite.com"));

                message.Bcc.Add(new MailAddress("admin4@yoursite.com"));

     

                //Body can be Html or text format

                //Specify true if it  is html message

                message.IsBodyHtml = false;

     

                // Message body content

                message.Body = txtMessage.Text;

     

                // Send SMTP mail

                smtpClient.Send(message);

     

                lblStatus.Text = "Email successfully sent.";

            }

            catch (Exception ex)

            {

                lblStatus.Text = "Send Email Failed.<br>" + ex.Message;

            }

    but it is not working.wat should i do. wat this line do .i want a proper copy paste which wll run .and i wll b able to send mail to any

    destination .plz help 

    Thursday, September 02, 2010 1:19 PM

Answers

  • Hi,

    Thanks for your post.

    For sending email in c#, please take a look at this thread. I posted complete sample there.

    BTW, please also consider http://forums.asp.net/ as an option.


    Please mark the right answer at right time.
    Thanks,
    Sam
    • Marked as answer by SamAgain Thursday, September 09, 2010 9:35 AM
    Friday, September 03, 2010 2:44 AM

All replies

  • What is the Exception message you are getting?

    What OS is your web server running on?  Windows XP Professional, Windows Server 2003 and Windows Server 2008 have the SMTP server as part of the OS.  Winodws Vista and Windows 7 do not have the SMTP server bundled.

    Even if you have the SMTP server, you have to turn on the service, and configure it properly to deliver mail.  If you can tell us more about the error message it will be easier to suggest solutions.

    kk

    Thursday, September 02, 2010 4:05 PM
  • hi ,i m using window xp professional,

    i m getting error msg as'' Failure sending mail.''

    plz give me the exact code.

    Thursday, September 02, 2010 5:58 PM
  • also i have done some setting web.config

    like

    <system.net>

    <mailSettings>

    <smtp>

    <network

    host="localhost"

    port="25"

    userName="username"

    password="password" />

    </smtp>

    </mailSettings>

    </system.net>

     

    what to write in username,password atribute

    Thursday, September 02, 2010 6:10 PM
  • Hi,

    Thanks for your post.

    For sending email in c#, please take a look at this thread. I posted complete sample there.

    BTW, please also consider http://forums.asp.net/ as an option.


    Please mark the right answer at right time.
    Thanks,
    Sam
    • Marked as answer by SamAgain Thursday, September 09, 2010 9:35 AM
    Friday, September 03, 2010 2:44 AM