MailMessage Problems

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

MailMessage Problems

 
0
  #1
Dec 2nd, 2008
Hey people , i am trying to send an email, but for some reason its just not sending ... please help me out , here's my code

  1.  
  2. // trying this block of code
  3. try
  4. {
  5. // Looping through the rows in the datatable
  6. foreach (DataRow Row in dt.Rows)
  7. {
  8. //declaring strings to hold the values
  9. string camp_code = Row["Campaign_Code"].ToString();
  10. string camp_name = Row["Campaign_Name"].ToString();
  11. string comapny_name = Row["company"].ToString();
  12. string email_address = Row["email"].ToString();
  13.  
  14. //settind txtTo.text to the value in the email string variable
  15. txtTo.Text = email_address;
  16.  
  17. // Declaring a new instance of a mail message
  18. MailMessage E_Mail_Message = new MailMessage();
  19.  
  20. //MailAddress MA = new MailAddress("info@place.co.za");
  21.  
  22. // Adding the To address to the mail message
  23. // The to address is = txtTo.Text
  24. E_Mail_Message.To.Add(new MailAddress(txtTo.Text));
  25.  
  26. // Setting the body of the email message
  27. // The body is = txtMessage.Text
  28. E_Mail_Message.Body = txtMessage.Text;
  29.  
  30. // Setting the subject of the email message
  31. // The subject is = txtSubject.Text
  32. E_Mail_Message.Subject = txtSubject.Text;
  33.  
  34. // Setting the from address of the email message
  35. // The from address is = txtFrom.Text
  36. E_Mail_Message.From = new MailAddress(txtFrom.Text);
  37.  
  38. // Declaring an instance of a SMTP client
  39. SmtpClient SMTP = new SmtpClient("smtp.place.com", 25);
  40.  
  41.  
  42.  
  43.  
  44. if (CB_Authentication.Checked == true)
  45. {
  46. // Setting SMTP Default credentials to false
  47. SMTP.UseDefaultCredentials = false;
  48.  
  49. // Adding new Credentials
  50. System.Net.NetworkCredential theCredential = new System.Net.NetworkCredential(txtUsername.Text, txtPassword.Text);
  51.  
  52. // setting smtp credentials to the new credentials
  53. SMTP.Credentials = theCredential;
  54. }
  55.  
  56. if (cboPorts.Text == "SMTP")
  57. {
  58. SMTP.Port = 25;
  59. }
  60.  
  61. if (cboPorts.Text == "POP")
  62. {
  63. SMTP.Port = 110;
  64. }
  65.  
  66. if (cboPorts.Text == "FTP")
  67. {
  68. SMTP.Port = 21;
  69. }
  70.  
  71. if (cboPorts.Text == "HTTP")
  72. {
  73. SMTP.Port = 80;
  74. }
  75.  
  76. SMTP.Send(E_Mail_Message);
  77. txtTo.Text = "";
  78. }
  79.  
  80. }
  81. catch (Exception EX)
  82. {
  83. MessageBox.Show("Sorry it didnt work");
  84. }
  85.  
  86. }

this email sends via a CSV file that is imported to a datatable (dt)
Last edited by cVz; Dec 2nd, 2008 at 10:20 am.
Delphi & C# programmer deluxe...
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: MailMessage Problems

 
0
  #2
Dec 2nd, 2008
Nevermind it does work , it sent to my junk folder , i never saw it , thank you guys ....
Delphi & C# programmer deluxe...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 623
Reputation: Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough 
Solved Threads: 101
Murtan Murtan is offline Offline
Practically a Master Poster

Re: MailMessage Problems

 
0
  #3
Dec 2nd, 2008
That looks like a mass-mailing application...not sure I WANT to help, but does it just not work or are you getting an exception?

If you're getting an exception, what is it?

If it just "doesn't work", what debugging (to ensure you are getting the right parameters set) have you done?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: MailMessage Problems

 
0
  #4
Dec 2nd, 2008
Originally Posted by Murtan View Post
That looks like a mass-mailing application...not sure I WANT to help, but does it just not work or are you getting an exception?

If you're getting an exception, what is it?

If it just "doesn't work", what debugging (to ensure you are getting the right parameters set) have you done?

thanks dude, it works, and you are right, mass mailing , not for spamming though...
Delphi & C# programmer deluxe...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC