narasiman rao

narasiman rao

  • NA
  • 519
  • 768.9k

Send Excel file to email for two different persons

Aug 27 2016 2:28 AM
  My code as follows

public void Getfunction(int j)
{
string connectionstring = "Server=(local);initial catalog=Test;Trusted_Connection=True";
SqlConnection sqlConnection = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
DataSet ds = new DataSet();
cmd.CommandText = "select * from Empdetails";
cmd.CommandText += " where shifttype = @par ";
cmd.Parameters.Add("@par", SqlDbType.Int).Value = j;
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection;
sqlConnection.Open();
reader = cmd.ExecuteReader();

if (reader.HasRows)
{
System.IO.StreamWriter sw_In = new System.IO.StreamWriter(@"C:\Users\God\Desktop\DataDump\" + j + "Excel.xls");
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
sw_In.AutoFlush = true;
sw_In.Write(reader[i].ToString() + "\t");
}
sw_In.Write("\n");
}

}
sqlConnection.Close();
reader.Close();
}



static void Main(string[] args)
{

Program ps = new Program();
int[] numbers = { 1, 2 };
foreach (int j in numbers)
{
ps.Getfunction(j);
System.Console.Write("{0} ", j);
}
}
 
MailMessage mis = new MailMessage();
SmtpClient smtpserver = new SmtpClient("smtp.gmail.com");
smtpserver.Credentials = new System.Net.NetworkCredential("[email protected]", "12345");
smtpserver.Host = "smtp.gmail.com";
smtpserver.Port = 587;
smtpserver.EnableSsl = true;
mis.From = new MailAddress("[email protected]", "Report");
mis.IsBodyHtml = true;
mis.To.Add("[email protected]");
mis.CC.Add(new MailAddress("[email protected]"));
mis.Subject = "DataDUmp send ing excel file error";
smtpserver.Send(mis);
mis.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
 
 
When i run the above code in Desktop under datadump folder 2 excel has been downloaded
in the name of 1Excel, 2Excel.

i want to send the above two excel to mail
1EXcel to send mail to [email protected]
2Excel to send mail to [email protected]

for that how can i send the above 2 excel to two different persons send mail in c#
 
for sending mail to two excel i write the above code, in that above code what changes to be done. i want the 1Excel to send to [email protected], and 2Excel to send to [email protected]
 

Answers (1)