Click here to Skip to main content
15,889,889 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone please advise where I am going wrong. Thanks a ton.

I am sure all the details were correct. Still i am getting exception and I have no clue who is the culprit.

Thanks a lot.
C#
protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        

            mail.From = new MailAddress(TextBoxEmail.Text, TextBoxCompanyName.Text);
            mail.To.Add(new MailAddress("indra.rikkala@achirconsultancy.com"));
           
            mail.Subject = TextBoxSubject.Text;
            mail.Body = TextBoxMessage.Text;

        SmtpClient client
            = new SmtpClient("smtp.achirconsultancy.com");
        client.Credentials = new System.Net.NetworkCredential("indra.rikkala@achirconsultancy.com", "zzzzzzzz");
        try
        {
           
            client.Port = 25;
            client.Send(mail);
        }
        catch (Exception ex) 
        {
            Labeltext.Text = " Error occured. Sorry for the inconvinence";
            return;
            /*Response.Write(" Unhandled expection occured please check the Email ID that you have entered");*/

        }

        Labeltext.Text = "Your message has been successfully sent. Thank you";
               
    }
Posted
Updated 25-Jun-10 10:40am
v3
Comments
Sandeep Mewara 26-Jun-10 7:51am    
Comments feature is specifically designed to interact with particular person and his answer. Why are you posting your discussion comments as answers? Stop it!

What exception you are getting?
Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>

If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]

If needed, there are lots of article on this very site on how to send emails
 
Share this answer
 
v2
Comments
Jayadheer Reddy 26-Jun-10 3:36am    
Reason for my vote of 5
Perfect and detailed
Is it mandatory to include SMTP configuration details in web.config.
I am pretty sure I have achieved it even without that.exception was connect failure.

Is that mean the in credential section I am giving wrong details?
 
Share this answer
 
Comments
Sandeep Mewara 26-Jun-10 7:50am    
Comments feature is specifically designed to interact with particular person and his answer. Why are you posting your discussion comments as answers?
I don't see anyplace in your code where you set the Host property of the client object. That's required, along with the Port property that you have set. Check here[
 
Share this answer
 
Comments
Dalek Dave 26-Jun-10 10:38am    
Why backslashes before apostrophes?
Roger Wright 26-Jun-10 10:42am    
I didn't put them there. It's a bug I reported last night, possibly something related to using Opera for posting here. When I type it and preview it, the post looks fine, but when it appears the slashes are inserted. I suspect that Chris has reverted to VBScript again...
What is the exception or error message tell you?
 
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