Click here to Skip to main content
13,004,397 members (73,817 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i used below coding to send mail from my own website but unable to send

           var fromAddress = "";
           var toAddress = txtfrmmailid.Text.ToString();
           string fromPassword ="mypassword";
           string subject = txtsubject.Text.ToString();
           string body = "From: Carshop\n";
           body += "Email:\n";
           body += "Subject: " + txtsubject.Text + "\n";
           body += "Message: \n" + txtcomments.Text + "\n";
           // smtp settings
           var smtp = new System.Net.Mail.SmtpClient();
               smtp.Host = "";
               smtp.Port = 25;
               smtp.EnableSsl = true;
               smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
               smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
               smtp.Timeout = 20000;
           // Passing values to smtp object
           smtp.Send(fromAddress, toAddress, subject, body);
       catch (Exception err)

private void errormessage(string msg)
       Response.Write("<script type=Text/Javascript> alert('" + msg + "'); </script>");
Posted 3-Jan-13 1:09am
Updated 3-Jan-13 1:20am
aspnet_regiis -i 3-Jan-13 7:13am
Since you have not posted the error message, I am unable to understand what might the problem may be...
Umapathi K 3-Jan-13 7:20am
error message like
Failure to send mail
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The code I use (which works for me) is here: Sending an Email in C# with or without attachments: generic routine.[^] - it's not that different from yours, but you might find it easier to start with known working code!
Umapathi K 3-Jan-13 7:22am
i am getting problem in port number of my website
OriginalGriff 3-Jan-13 7:28am
Then you need to check with your hosting service.
Most SMTP traffic does go on Port 25, but they can change that and some do for security reasons, and if you are on a POP server rather than SMTP it would be 110. If it isn't standard, then the host documentation will normally tell you pretty clearly.
Have you tried without specifying the port?
Umapathi K 3-Jan-13 7:30am
how to find port for my website
OriginalGriff 3-Jan-13 7:35am
It's not something you can specify - whoever installed the email engine that you are using will set up the port values (and open the appropriate holes in the firewall). It isn't a value you decide, you have to ask the hosting company that your site is working on - they will tell you, particularly if it is not standard.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

if you got above code form any portal then there should be issue with your antivirus settings

some of antivirus are blocking this kind to sending email. as I face it before so it may be the issue.

have a look and let me know :)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100