Click here to Skip to main content
15,885,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i used below coding to send mail from my own website but unable to send

C#
try
       {

           var fromAddress = "contactus@investemu.com";

           var toAddress = txtfrmmailid.Text.ToString();

           string fromPassword ="mypassword";

           string subject = txtsubject.Text.ToString();
           string body = "From: Carshop\n";
           body += "Email: contactus@investemu.com\n";
           body += "Subject: " + txtsubject.Text + "\n";
           body += "Message: \n" + txtcomments.Text + "\n";
           // smtp settings
           var smtp = new System.Net.Mail.SmtpClient();
           {
               smtp.Host = "smtp.investemu.com";
               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)
       {
           errormessage(err.Message);
       }



C#
private void errormessage(string msg)
   {
       Response.Write("<script type=Text/Javascript> alert('" + msg + "'); </script>");
   }
Posted
Updated 3-Jan-13 1:20am
v3
Comments
bbirajdar 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

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!
 
Share this answer
 
Comments
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.
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 :)
 
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