1
I’m trying to send a newsletter to all users who have enabled the newsletter and I’m not getting.
My code to send one email normal 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 go to search all the database mails whose they have newsletter active, that is to say SELECT EMAIL FROM UTILIZADORES WHERE NEWSLETTER = 'TRUE'
.
How can I do that, so that the msg.To.Add(toAddress);
just send mails for the users with newsletter active?
Could you exemplify it in a more complex way? I have tried it in several ways but without success.
– Chirag Geiantilal
In which part are you having difficulties?
– Armando K.
In the selection of the emails of the users who have the newsletter active. I have tried several ways within Try and could not. I tried to put sql command in string to address and it also didn’t work like this.
– Chirag Geiantilal
I updated the answer, now see if the answer is clearer.
– Armando K.
Have some way to do via stored Procedure?
– Chirag Geiantilal