I'm trying to send a newsletter to all users who have the newsletter enabled and I can not.
My normal send email code is:
try
{
SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = false;
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "msg");
smtp.EnableSsl = true;
MailMessage msg = new MailMessage();
msg.Subject = "msg | Newsletter | " + txtAssunto.Text + " - msg";
msg.Body = "Msg";
string toAddress = ????
msg.To.Add(toAddress);
string fromAddress = "\"msg";
msg.From = new MailAddress(fromAddress);
msg.IsBodyHtml = true;
smtp.Send(msg);
} catch {
}
How can I get all the mails of which have newsletter active, ie SELECT EMAIL FROM UTILIZADORES WHERE NEWSLETTER = 'TRUE'
.
How can I do this, so that msg.To.Add(toAddress);
only sends mails to users with newsletter active?