Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
i used below coding to send mail from my own website but unable to send
 
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);
       }
 

private void errormessage(string msg)
   {
       Response.Write("<script type=Text/Javascript> alert('" + msg + "'); </script>");
   }
Posted 3-Jan-13 1:09am
Edited 3-Jan-13 1:20am
v3
Comments
aspnet_regiis -i at 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 at 3-Jan-13 7:20am
   
error message like
Failure to send mail
Rate this: bad
good
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!
  Permalink  
Comments
Umapathi K at 3-Jan-13 7:22am
   
i am getting problem in port number of my website
OriginalGriff at 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 at 3-Jan-13 7:30am
   
how to find port for my website
OriginalGriff at 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
good
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 Smile | :)
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 470
1 Gihan Liyanage 317
2 ClimerChinna 182
3 vikinghunter 176
4 OriginalGriff 141
0 Sergey Alexandrovich Kryukov 8,653
1 OriginalGriff 7,132
2 CPallini 2,598
3 Richard MacCutchan 2,060
4 Abhinav S 1,808


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
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