Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我的电子邮件发送,但没有表格标题_C# - Fatal编程技术网

C# 我的电子邮件发送,但没有表格标题

C# 我的电子邮件发送,但没有表格标题,c#,C#,//这是我的按钮发送事件// 私有无效BTN发送\单击(对象发送方,事件参数e) { 尝试 { //这是我成功发送的html文件,但没有表头// string mailBody = "<HTML><Body><table width='100%' style='border:Solid 1px Black;'>"; foreach (DataGridViewRow row in dataGrid

//这是我的按钮发送事件//
私有无效BTN发送\单击(对象发送方,事件参数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);
            }
string mailBody=“”;
foreach(dataGridView3.Rows中的DataGridViewRow行)
{
邮件正文+=“”;
foreach(row.Cells中的DataGridViewCell单元格)
{
邮件正文+=“”+单元格.值+“”;
}
邮件正文+=“”;
}
邮件正文+=“”;
//html表单到此结束//
Outlook.\u应用程序\u应用程序=新建Outlook.Application();
Outlook.MailItem邮件=(Outlook.MailItem)\ u app.CreateItem(Outlook.OlItemType.olMailItem);
mail.To=txtTo.Text;
mail.Subject=txtSubject.Text;
//mail.Body=mailBody;
mail.HTMLBody=邮件正文;
mail.Importance=Outlook.OlImportance.olImportanceNormal;
((Outlook._MailItem)mail).Send();
MessageBox.Show(“您的邮件已成功发送。”,“Message”,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
捕获(例外情况除外)
{
MessageBox.Show(例如Message,“Message”,MessageBoxButtons.OK,MessageBoxIcon.Error);
}

//“我的电子邮件”发送正文中的数据,但datagridview的表格不显示表格标题。//

如果您只是在查找HTML标题标记,您将使用TH元素,如下所示:


表头1表头2
表单元格1表单元格2
private void btn发送\u单击(对象发送者,事件参数e)
{
字符串mailBody=“”;
foreach(dataGridView3.Columns中的DataGridViewColumn列)
{
邮件正文+=“”;
foreach(row.Cells中的DataGridViewCell单元格)
{
邮件正文+=“”+单元格.值+“”;
}
邮件正文+=“”;
}
邮件正文+=“”;
Outlook.\u应用程序\u应用程序=新建Outlook.Application();
Outlook.MailItem邮件=(Outlook.MailItem)\ u app.CreateItem(Outlook.OlItemType.olMailItem);
尝试
{
mail.To=txtTo.Text;
mail.Subject=txtSubject.Text;
mail.HTMLBody=mailBody;
mail.Importance=Outlook.OlImportance.olImportanceNormal;
((Outlook._MailItem)mail).Send();
MessageBox.Show(“您的邮件已成功发送。”,“Message”,MessageBoxButtons.OK,MessageBoxIcon.Information);
txtTo.Clear();
txtSubject.Clear();
}
捕获(例外情况除外)
{
MessageBox.Show(例如Message,“Message”,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}

//这对我来说终于奏效了。

我不明白你的问题是什么。如果你想在邮件正文中使用HTML,那么告诉它
mail.IsBodyHtml=true;
你的问题不太清楚。请编辑问题以添加示例输入和预期输出。例如,当你传递一个特定的HTML时,你是如何期望的ng以查看mailHi All。我的代码确实发送了一封电子邮件。正文是HTML,它显示从datagridview提取的数据,但没有表标题。例如,每列都有一个标题。我正在尝试显示列标题以及提取的单元格。在定义表时,您不添加任何标题。我确信您可以使用您的收藏夹e搜索引擎找到一个关于HTML代码的指南,用于带有标题的表,有无数的可用资源。。。
    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);
        }
    }