//这是我的按钮发送事件//
private void btnSend_Click(object sender,EventArgs e)
{
尝试
{
//这是我的html文件,它成功发送但没有表格标题//
string mailBody = "<HTML><Body><table width='100%' style='border:Solid 1px Black;'>";
foreach (DataGridViewRow row in dataGridView3.Rows)
{
mailBody += "<tr>";
foreach (DataGridViewCell cell in row.Cells)
{
mailBody += "<td style='color:blue;'>" + cell.Value + "</td>";
}
mailBody += "</tr>";
}
mailBody += "</table></Body></HTML>";
//The html form ends here//
Outlook._Application _app = new Outlook.Application();
Outlook.MailItem mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
mail.To = txtTo.Text;
mail.Subject = txtSubject.Text;
//mail.Body = mailBody;
mail.HTMLBody = mailBody;
mail.Importance = Outlook.OlImportance.olImportanceNormal;
((Outlook._MailItem)mail).Send();
MessageBox.Show("Your Message has been successfully sent.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//我的电子邮件发送正文中的数据,但datagridview的表格没有显示表格标题.//
答案 0 :(得分:1)
如果您只是在寻找HTML标头标签,那么您可能希望使用TH元素,类似于以下内容:
<TABLE BORDER='1'>
<TR><TH>Table Header 1</TH><TH>Table Header 2</TH></TR>
<TR><TD>Table Cell 1</TD><TD>Table Cell 2</TD></TR>
</TABLE>
如果没有进一步的信息,我们无法在这里提供太多的输入 - 我们需要预期的输入/输出,此时我们只能假设。
答案 1 :(得分:0)
private void btnSend_Click(object sender, EventArgs e)
{
string mailBody = "<HTML><Head><Body><table width='100%' style='border:Solid 1px Black;'>";
foreach (DataGridViewColumn Column in dataGridView3.Columns)
{
mailBody += "<td style=font -size:100%'><b>" + Column.HeaderText + "</b></td>";
}
foreach (DataGridViewRow row in dataGridView3.Rows)
{
mailBody += "<tr style=font - size:150 % '>";
foreach (DataGridViewCell cell in row.Cells)
{
mailBody += "<td style='color:black;'>" + cell.Value + "</td>";
}
mailBody += "</tr>";
}
mailBody += "</Head></table></Body></HTML>";
Outlook._Application _app = new Outlook.Application();
Outlook.MailItem mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
try
{
mail.To = txtTo.Text;
mail.Subject = txtSubject.Text;
mail.HTMLBody=mailBody;
mail.Importance = Outlook.OlImportance.olImportanceNormal;
((Outlook._MailItem)mail).Send();
MessageBox.Show("Your Message has been successfully sent.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtTo.Clear();
txtSubject.Clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//这就是我最终的作品。