Outlook MailItem HTML Formatting Dropdown

378 views Asked by At

I am currently writing a C# script to send an email.

I am using the mailitem.htmlbody and my table is being formatted correctly.

However, when I added a dropdown to it, the dropdown doesn't work.

The HTML works, I am inclined to believe it is something with Outlook or 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

There are 1 answers

3
Eugene Astafiev On BEST ANSWER

A well-known fact is that Outlook uses Word for rendering HTML markup. You can read about supported and unsupported HTML elements, attributes, and cascading style sheets properties in the following series of articles in MSDN: