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

// trying this block of code
            try
            {
                // Looping through the rows in the datatable
                foreach (DataRow Row in dt.Rows)
                {
                    //declaring strings to hold the values
                    string camp_code = Row["Campaign_Code"].ToString();
                    string camp_name = Row["Campaign_Name"].ToString();
                    string comapny_name = Row["company"].ToString();
                    string email_address = Row["email"].ToString();

                    //settind txtTo.text to the value in the email string variable
                    txtTo.Text = email_address;

                    // Declaring a new instance of a mail message
                    MailMessage E_Mail_Message = new MailMessage();

                    //MailAddress MA = new MailAddress("info@place.co.za");

                    // Adding the To address to the mail message
                    // The to address is = txtTo.Text
                    E_Mail_Message.To.Add(new MailAddress(txtTo.Text));

                    // Setting the body of the email message
                    // The body is = txtMessage.Text
                    E_Mail_Message.Body = txtMessage.Text;

                    // Setting the subject of the email message
                    // The subject is = txtSubject.Text
                    E_Mail_Message.Subject = txtSubject.Text;

                    // Setting the from address of the email message
                    // The from address is = txtFrom.Text
                    E_Mail_Message.From = new MailAddress(txtFrom.Text);

                    // Declaring an instance of a SMTP client
                    SmtpClient SMTP = new SmtpClient("smtp.place.com", 25);

                    


                    if (CB_Authentication.Checked == true)
                    {
                        // Setting SMTP Default credentials to false
                        SMTP.UseDefaultCredentials = false;

                        // Adding new Credentials
                        System.Net.NetworkCredential theCredential = new System.Net.NetworkCredential(txtUsername.Text, txtPassword.Text);

                        // setting smtp credentials to the new credentials
                        SMTP.Credentials = theCredential;
                    }

                    if (cboPorts.Text == "SMTP")
                    {
                        SMTP.Port = 25;
                    }

                    if (cboPorts.Text == "POP")
                    {
                        SMTP.Port = 110;
                    }

                    if (cboPorts.Text == "FTP")
                    {
                        SMTP.Port = 21;
                    }

                    if (cboPorts.Text == "HTTP")
                    {
                        SMTP.Port = 80;
                    }

                    SMTP.Send(E_Mail_Message);
                    txtTo.Text = "";
                }

            }
            catch (Exception EX)
            {
                MessageBox.Show("Sorry it didnt work");
            }

}

this email sends via a CSV file that is imported to a datatable (dt)

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?

Nevermind it does work , it sent to my junk folder , i never saw it , thank you guys ....

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.