7
Answers

Sending emails from database in C#

Ask a question
Mark Fenech

Mark Fenech

13y
4.6k
1
Hi im working on a software project with C# im stuck with this problem sending emails to specific emails works great now what i want is when i tick a checkbox emails from a table in database get in the add to Message etc...... this is my code:

  SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                smtp.EnableSsl = true;
                smtp.Timeout = 10000;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "mypassword");

                message.From = new MailAddress("[email protected]", "Mark Fenech");
                if (chcbox_members.Checked)
                {
                    message.To.Add(// here im adding the db Code to Select Email from tblMember
                }
                else
                {
                message.To.Add(txt_emailTo.Text);
                }
                message.Subject = txt_Subject.Text;
                message.Body = label9.Text + "   " + label5.Text + "\n"+ label10.Text + "   " + label6.Text + "\n" + label11.Text + "   " + label7.Text+ "\n" + label12.Text + "   "+ label8.Text;
                message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                smtp.Send(message);


This is an image of te design so you can understand more : http://i55.tinypic.com/wbtncm.jpg


Answers (7)