Click here to Skip to main content
16,017,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello sir,

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";
               
    }


Thanks a lot for helping me on "unable to send email in Asp.net" question

I have one last question can you please give me clarification on this topic.


I hosted my site in Discountasp.net.
Well, the problem in this code is port number.
If I change my port number from 25 to 587 it's working. Why so???
If it is 25 it is unable to communicate with the server.


And one more thing is it's working only if I supply the emails(both TO and FROM) of same domain(the domain I am working for). Can't I send mail to another person outside of my domain?

Lot of articles on this topic didn't mention to give username and password details in network credential section. Is that optional????

At network credential section in web.config file which username password details I have to supply? Is it the control panel of that domain? or just from address(email) username and password?


Sorry to ask these many questions but answers to these questions certainly give me what exactly I am doing.

Thanks for sharing your wisdom.
Posted
Updated 26-Jun-10 5:37am
v6

1 solution

Q: If I change my port number from 25 to 587 it's working. Why so???
If it is 25 it is unable to communicate with the server.

A: By default the SMTP server port is 25 but that can be changed, your SMTP server is configured at 587, it means it is listning on PORT 587, and if you want to communicate with your SMTP you should use PORT 587 only.


Q: And one more thing is it's working only if I supply the emails(both TO and FROM) of same domain(the domain I am working for). Can't I send mail to another person outside of my domain?

A: Yes you can, if it is not restricted by your administrator.

Q: At network credential section in web.config file which username password details I have to supply? Is it the control panel of that domain? or just from address(email) username and password?

A: Network credential to which your SMTP server is accessible. Ask your administrator.
 
Share this answer
 
v2

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