By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,551 Members | 2,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,551 IT Pros & Developers. It's quick & easy.

Problem sending mails

ThatThatGuy
Expert 100+
P: 449
Hello reader,,
This might be a very simple question, but what to just say about it, i'm facing it

Actually i'm developing a web App and i want email feature in that....
I'm sending mail from my development machine i.e localhost

This is the setting in web.config
Expand|Select|Wrap|Line Numbers
  1. <system.net>
  2.       <mailSettings>
  3.  
  4.         <smtp>
  5.           <network host="localhost" port="25" userName="reverso@gmail.com" password="somepassword" />
  6.         </smtp>
  7.       </mailSettings>
  8.     </system.net>
  9.  
and this is the code to send the email
Expand|Select|Wrap|Line Numbers
  1.         try
  2.         {
  3.             MailMessage mail = new MailMessage("from", "to","Some subject", "Mail Body");
  4.             SmtpClient sm = new SmtpClient("localhost", 25);
  5.             sm.Send(mail);
  6.             Page.Controls.Add(new LiteralControl("<script language='javascript'> alert('Mail Sent Successfully'); </script>"));
  7.  
  8.         }
  9.         catch (Exception rr)
  10.         {
  11.             Page.Controls.Add(new LiteralControl("<script language='javascript'> alert('" + rr.Message + "'); </script>"));
  12.         }
  13.  
Actually im facing problem sending mail plz someone verify this code
whether is it proper or not...
I'm getting failure sending mail error every time....
Plz help me with this it's urgent....
Aug 28 '09 #1
Share this Question
Share on Google+
2 Replies


ssnaik84
100+
P: 149
- is mail server configured on your localhost?
- whats the exception?
- new MailMessage("from", "to" ......... "from", "to" should be email address not normal string
Aug 31 '09 #2

Frinavale
Expert Mod 5K+
P: 9,731
@ThatThatGuy

In line 3 of your C# code you should be passing it the email address (maybe the one stored in the web.config) as the From parameter.

You also need to pass a valid email address as the To parameter.

If you're using the gmail account to send email messages then you're going to have to use a NetworkCredential Object to provide the credentials for your gmail account.

Check out this Quick Reference on how to send an email using .NET for more information.
Aug 31 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.