Dear Sir,
i want to send email all user whoese in my database .
i want to send also user name and password for login to users ..
how to get value from while loop with datareader ..
following my code .. i get all email throw i but i dont know to get username and password also ..
thanks and regards.
protected void btnSendEmail_Click(object sender, EventArgs e)
{
if (txtemailfrom.Text == "")
{
lblmail.Text = "Please fill all mandatory fields.";
lblmail.Visible = true;
return;
}
ArrayList list_emails = new ArrayList();
int i = 0;
string email,uname,pass;
con.Open();
SqlCommand cmd = new SqlCommand("Select email,password,username from Information", con);
SqlDataReader read_Email = cmd.ExecuteReader();
while (read_Email.Read())
{
//how to read particular username and password of that user and use it in mail function
email = read_Email.GetValue(i).ToString();
list_emails.Add(email); //Add email to a arraylist
i = i + 1 - 1;
}
read_Email.Close();
con.Close(); //Close connection
foreach (string email_to in list_emails)
{
string message = "hello";
string FromAddress = txtemailfrom.Text;
MailMessage MailBody = new MailMessage();
MailBody.IsBodyHtml = true;
MailBody.From = new MailAddress(FromAddress, "domain.com", System.Text.Encoding.UTF8);
MailBody.Subject = "Welcome To India";
MailBody.SubjectEncoding = System.Text.Encoding.UTF8;
MailBody.Body = message;
MailBody.BodyEncoding = System.Text.Encoding.UTF8;
MailBody.Priority = MailPriority.Normal;
SmtpClient SMTPHOST = new SmtpClient();
SMTPHOST.EnableSsl = false;
SMTPHOST.UseDefaultCredentials = true;
SMTPHOST.Credentials = new NetworkCredential(FromAddress, "password");
SMTPHOST.Host = "server name";
SMTPHOST.Send(MailBody);
}
thnks in advance..