Outlook MailItem HTML格式下拉列表

时间:2015-06-09 17:22:10

标签: c# html outlook

我目前正在编写一个C#脚本来发送电子邮件。

我正在使用mailitem.htmlbody,我的表格格式正确。

但是,当我添加一个下拉列表时,下拉列表不起作用。

HTML有效,我倾向于认为它与Outlook或C#有关。

private void sendEmail_Click(object sender, EventArgs e)
    {   
        if (tabControl1.SelectedIndex == 0)
        {
            if (dataGridTransactions.SelectedRows.Count > 0)
            {
                string recordOwner = dataGridTransactions.SelectedRows[0].Cells[1].Value.ToString();
                string[] recordOwner1;
                recordOwner1 = recordOwner.Split();
                Outlook.Application application = null;
                application = new Outlook.Application();
                Outlook.MailItem mailItem = (Outlook.MailItem)
                    application.CreateItemFromTemplate("PATH");
                mailItem.Subject ="Auditing Skype, Cell, VOIP, and Glance Logs";
                mailItem.To = recordOwner1[0] + "." + recordOwner1[1] + "@hbmncode.com";
                string htmlString = "<HTML><Body><p>BODY TEXT.</p></body>";
                string htmlTable = "<table runat=server id=Table1 border=1 class=style1><tr><td class=style2 colspan=1>Transaction Type</td><td class=style2 colspan=1>Number/Skype/Name</td><td class=style2>Total Transactions</td><td class=style2 rowspan=1>Outgoing</td><td class=style2>Incoming</td><td class=style2>Date/Time Most Recent Transaction</td><td class=style2>Category</td><td class=style2>Notes</td></tr>";
                for (int i = 0; i < dataGridTransactions.SelectedRows.Count; i++)
                {
                  string name;
                  int cnt = 0;
                  int cntIn = 0;
                  int cntOut = 0;
                  string now = "06/09/2015 10:08";
                  string dropDown = "<form><select><option style=display:none>Choose an item</option><option>Employee</option><option>Affiliate</option><option>Non-Affiliate</option></select></form>";
                  DateTime dateRecent = Convert.ToDateTime(now);
                  if (dataGridTransactions.SelectedRows[i].Cells[2].Value.ToString() == "Phone Call")
                  {
                      name = dataGridTransactions.SelectedRows[i].Cells[8].Value.ToString();
                      cnt = 0;
                      cntIn = 0;
                      cntOut = 0;
                      dateRecent = Convert.ToDateTime(dataGridTransactions.SelectedRows[i].Cells[10].Value.ToString());
                      for (int j = 0; j < dataGridTransactions.SelectedRows.Count; j++)
                      {
                          if (name == dataGridTransactions.SelectedRows[j].Cells[8].Value.ToString())
                          {
                              cnt++;
                              if (dataGridTransactions.SelectedRows[j].Cells[9].Value.ToString() == "Incoming Call")
                              {
                                  cntIn++;
                              }
                              else
                              {
                                  cntOut++;
                              }
                              if(Convert.ToDateTime(dataGridTransactions.SelectedRows[j].Cells[10].Value.ToString()) > dateRecent)
                              {
                                  dateRecent = Convert.ToDateTime(dataGridTransactions.SelectedRows[j].Cells[10].Value.ToString());
                              }
                          }
                      }
                  }
                  else if (dataGridTransactions.SelectedRows[i].Cells[2].Value.ToString() == "VOIP Call")
                  {
                      name = dataGridTransactions.SelectedRows[i].Cells[7].Value.ToString();
                  }
                  else if (dataGridTransactions.SelectedRows[i].Cells[2].Value.ToString() == "Glance")
                  {
                      name = dataGridTransactions.SelectedRows[i].Cells[4].Value.ToString();
                  }
                  else
                  {
                      name = dataGridTransactions.SelectedRows[i].Cells[14].Value.ToString();
                  }
                  if (htmlTable.Contains(name))
                  {
                      continue;
                  }
                  else
                  {
                      htmlTable = htmlTable + ("<tr><td class=style2>" + dataGridTransactions.SelectedRows[i].Cells[2].Value.ToString() + "</td><td class=style2>" + name + "</td><td class=style2>"+cnt+"</td><td class=style2>"+cntOut+"</td><td class=style2>"+cntIn+"</td><td class=style2>"+dateRecent+"</td><td class=style2>"+dropDown+"</td><td class=style2></td></tr>");
                  }
             }

                mailItem.HTMLBody = htmlString+"<br /><br />"+htmlTable+"</table></HTML>";
                mailItem.Display(false);
            }
            else
            {
                MessageBox.Show("Please select a Record Owner to email.",
                                "Error!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

一个众所周知的事实是Outlook使用Word来呈现HTML标记。您可以在MSDN的以下系列文章中阅读受支持和不受支持的HTML元素,属性和级联样式表属性: