I want to insert database content in Email body, index 0 of data reader which contain id number for each email address, I want to send mail using add id number in mail body for instance: The Employee id is 5. I need insert each id on each mail body which exist in same row. I have used this code to insert id in body but that didn't work
message.Body = "The Employee id is 5 "+reader[1].ToString();
Full code is:
MailMessage message = new MailMessage();
message.Subject = "Employee Access ";
message.From = new MailAddress("avvv@gmail.com");
var fromAddress = "avvv@gmail.com";
const string fromPassword="password";
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
OleDbCommand cmd = null;
OleDbCommand cmd2 = null;
string queryString = "select id,email,status from tableemail";
using (OleDbConnection connection = new OleDbConnection("Provider = OraOLEDB.Oracle.1; Data Source = xe;
Password=654321;User ID = xpress; unicode=true"))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
connection.Open();
cmd = new OleDbCommand(queryString);
cmd.Connection = connection;
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
MailAddress to = new MailAddress(reader[1].ToString());
message.To.Add(to);
}
message.Body = "The Employee id is 5 "+reader[1].ToString();
smtp.Send(message);
reader.Close();
}
}
Can I insert multiple database field in body using data reader?