Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wbk = xlapp.Workbooks.Open(@"D:\\" + file_name);
Microsoft.Office.Interop.Excel.Worksheet wsht = wbk.Worksheets[1];
Microsoft.Office.Interop.Excel.Range source = wsht.UsedRange;
int lastrow = source.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Row;
body=body+"<table border='1' bordercolor='solid black'>";
for (int i = 1; i <= lastrow;i++)
{
string bgcolor = "", fontcolor="";
if(i==1)
{
bgcolor = "#1885CB";
fontcolor = "#FDFDFD";
}
else if (i ==lastrow)
{
bgcolor = "#E85815";
fontcolor = "#020000";
}
else
{
bgcolor = "#FDFDFD";
fontcolor = "#020000";
}
string col1=wsht.Range["A" + i].Text.ToString();
string col2 = wsht.Range["B" + i].Text.ToString();
body = body + "<tr><td align='center' bgcolor='" + bgcolor + "' width='100px'><font color='" + fontcolor + "' face='Calibri'>" + col1 + "</font></td><td align='center' bgcolor='" + bgcolor + "' width='100px'><font color='" + fontcolor + "' face='Calibri'>" + col2 + "</font></td></tr>";
}
body = body + "</table></br>";
wbk.Close();
wbk = null;
xlapp.Quit();
xlapp = null;
Since the body of the mail also changes on condition.