Connecting Tech Pros Worldwide Help | Site Map

In sending data to email, can anyone help me check if I made mistake anywhere....

Newbie
 
Join Date: Oct 2009
Location: Malaysia
Posts: 9
#1: Oct 14 '09
Hai there,

Check whether I configure it correctly...

Expand|Select|Wrap|Line Numbers
  1. myMsg.To.Add("some1@hotmail.com");
  2. myMsg.From = new MailAddress("admin@emailserver.com");
  3. smtp.Host = "mail.emailserver.com";
  4. NetworkCred.UserName = "admin@emailserver.com";
And can explain me what is this 4 actually?

Expand|Select|Wrap|Line Numbers
  1. MailMessage myMsg = new MailMessage();
  2.         myMsg.To.Add("some1@hotmail.com");
  3.         //TODO: Armour plate this method 
  4.         myMsg.From = new MailAddress("admin@emailserver.com");
  5.         myMsg.Subject = "Subject";
  6.         myMsg.Body = "Name : " + txtName.Text +
  7.         "\n Designation : " + txtDesignation.Text +
  8.         "\n Organisation : " + txtOrganisation.Text +
  9.         "\n Contact Number : " + txtTel.Text +
  10.         "\n Facsimile: " + txtFax.Text +
  11.         "\n Email : " + txtEmail.Text +
  12.         "\n Choosen Courses : " + txtChoosen.Text; ;
  13.  
  14.         SmtpClient smtp = new SmtpClient();
  15.         smtp.Host = "mail.emailserver.com";
  16.         smtp.EnableSsl = false;
  17.         System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
  18.         NetworkCred.UserName = "admin@emailserver.com";
  19.         NetworkCred.Password = "password";
  20.         smtp.UseDefaultCredentials = true;
  21.         smtp.Credentials = NetworkCred;
  22.         //smtp.Port = 587;
  23.         smtp.Send(myMsg);       
  24.         lblConfirm.Text = "Thank you for your enquiry. We will get back to you as soon as possible. Have a nice day.";
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: Oct 14 '09

re: In sending data to email, can anyone help me check if I made mistake anywhere....


I'm sorry you're going to have to explain what the problem is in more detail.
The second chunk of code sends an email....

-Frinny
Newbie
 
Join Date: Oct 2009
Location: Malaysia
Posts: 9
#3: Oct 15 '09

re: In sending data to email, can anyone help me check if I made mistake anywhere....


Hai Frinny,

Actually I did not upload to server yet to test...
While im trying to test in my pc, it shows error like this...

Expand|Select|Wrap|Line Numbers
  1. An attempt was made to access a socket in a way forbidden by its access permissions 202.190.202.17:25 
  2. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  3.  
  4. Exception Details: System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 202.190.202.17:25
  5.  
  6. Source Error: 
  7.  
  8.  
  9. Line 50:         smtp.Credentials = NetworkCred;
  10. Line 51:         //smtp.Port = 587;
  11. Line 52:         smtp.Send(myMsg);
  12. Line 53:         lblConfirm.Text = "Thank you for your feedback/suggestion. We will get back to you as soon as possible. Have a nice day."; 
  13. Line 54:     }
  14.  
  15.  
  16. Source File: c:\Documents and Settings\VIHETHI\My Documents\Visual Studio 2008\VIHETHI_WEB\onlineReg.aspx.cs    Line: 52 
  17.  
  18.  
What should I do get it work whithout upload to server... Any configuration or setting should I do in my pc...

And the chunk 2 is the full codes.... to show you what I have done...

Chunk 1 is for wheter I key in email addresses and smt host correctly?

Thanks Frinny for your reply,

Meshack
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#4: Oct 15 '09

re: In sending data to email, can anyone help me check if I made mistake anywhere....


I've seen this error before. It had to do with the way that the network was configured, the port that I was trying to send the email on was blocked by the network that my application was residing in. I would recommend that you check all firewall and router settings to make sure that you can send an email on the port that you need to use to send emails.
Newbie
 
Join Date: Oct 2009
Location: Malaysia
Posts: 9
#5: Oct 15 '09

re: In sending data to email, can anyone help me check if I made mistake anywhere....


Thanks Frinny.
I will check that.
Thanks again.
Reply