Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
protected void Button1_Click(object sender, EventArgs e)
   {
       SmtpClient smtpClient = new SmtpClient("exchangeServerHTTPS", 25);
       System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
       try
       {
           MailAddress fromAddress = new MailAddress("operations@test.com", "From Me");
           MailAddress toAddress = new MailAddress("faxsv@test.com", "To You");
           message.From = fromAddress;
           message.To.Add(toAddress);
           message.Subject = "Testing!";
           message.Body = "This is the body of a sample message";
           smtpClient.UseDefaultCredentials = true;
           System.Net.NetworkCredential nc = CredentialCache.DefaultNetworkCredentials;
           smtpClient.Credentials = (System.Net.ICredentialsByHost)nc.GetCredential("exchangeServerHTTPS", 25, "Basic");
           smtpClient.Send(message);

           lblmsg.Text = "Email sent.";
       }
       catch (Exception ex)
       {
           lblmsg.Text = "Coudn't send the message!\n  " + ex.Message;
       }

   }

i am trying this code but its getting error while sending mail.
any one will help me about this.................
Posted
Updated 26-Jul-12 21:20pm
v2
Comments
StianSandberg 27-Jul-12 3:21am    
what error do you get?
Sandeep Mewara 28-Jul-12 0:08am    
Care to share the error?

1 solution

Since you wont give us any feedback I cant help you in any other way than give you a link to a web page tutorial for doing this:
http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx[^]

If you have more information that can help us understand your problem pleas sher the information with us by using the Improve question button. Thanks :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900