title: Html table output formatting when sending email from Microsoft Outlook using R
body: <p>I am trying to convert a dataframe into an html table using the <code>htmlTable</code> package and then send an email using Microsoft Outlook as the email client using <code>RDCOMClient</code> package by appending the html table as the body of the email. I am new to HTML coding so I am not very familiar with how to format the table with HTML tags. Below is an example of what I am trying to do. </p>
  
  <pre><code># Library to send email from Microsoft Outlook
  library(RDCOMClient)
  # Library to create HTML table
  library(htmlTable)
  
  # Reading data from inbuilt 'mtcars' dataset
  x &lt;- head(mtcars)
  
  # Create HTML table
  y &lt;- htmlTable(x,
                 rnames = FALSE,
                 caption="This is from htmlTable package",
                 align = paste(rep("c", ncol(x)), collapse = "|"),
                 align.header = paste(rep("c", ncol(x)), collapse = "|"))
  
  # add the table as body of the email
  body &lt;- paste0("&lt;html&gt;", y, "&lt;/html&gt;")
  
  ## init com api
  OutApp &lt;- COMCreate("Outlook.Application")
  ## create an email 
  outMail = OutApp$CreateItem(0)
  ## configure  email parameter 
  outMail[["To"]] = "test@test"
  outMail[["subject"]] = "TEST"
  outMail[["HTMLbody"]] = body
  ## send it                     
  outMail$Send()
  </code></pre>
  
  <p>This above code works and I even get the email output as shown below.</p>
  
  <p>Output from email sent using above code in Microsoft Outlook</p>
  
  <p><a href="https://i.stack.imgur.com/8Rrrl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Rrrl.png" alt="image description"></a></p>
  
  <p>My question is, how to I format this table? I want the output to be in a nice table format with row and columns separated by lines. I can add column separator lines as seen in the output, but I am unable to add row separator lines. I also want to adjust the line spacing between the rows and columns, and change the formatting of the fonts to calibri 11. Below is the output that I am looking for.</p>
  
  <p>Desired Output with rows and columns formatted
  <a href="https://i.stack.imgur.com/to0lS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/to0lS.png" alt="image description"></a></p>
  
  <p>Any help on how I can achieve this using <code>htmlTable</code> package or any other workaround would be really appreciated. Thanks a lot in advance.</p>
  
  <p><strong>UPDATE:</strong> Below is the solution, thanks to valuable inputs provided by @Syfer.</p>
  
  <pre><code>library(RDCOMClient)
  library(htmlTable)
  
  x &lt;- head(mtcars)
  html_y &lt;- htmlTable(x, rnames = FALSE)
  
  body &lt;- paste0("&lt;html&gt;&lt;head&gt;
                 &lt;style&gt;
                 body{font-family:Arial, \"sans-serif\";}
                 table{border-left:1px solid #000000;border-top:1px solid #000000;}
                 table td{border-right:1px solid #000000;border-bottom:1px solid #000000;font-size:12px; font-weight:normal;}
                 table th{border-right:1px solid #000000;border-bottom:1px solid #000000;font-size:14px;}
                 &lt;/style&gt;
                 &lt;/head&gt;&lt;body&gt;",
                 html_y, 
                 "&lt;/body&gt;&lt;/html&gt;")
  
  OutApp &lt;- COMCreate("Outlook.Application")
  outMail = OutApp$CreateItem(0)
  outMail[["To"]] = "test@test.com"
  outMail[["subject"]] = "TEST EMAIL"
  outMail[["HTMLbody"]] = body
  outMail$Send()
  </code></pre>
  
  <p>Final output in Microsoft Outlook likes this.</p>
  
  <p><a href="https://i.stack.imgur.com/fM0KU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fM0KU.png" alt="Final Output In Microsoft Outlook"></a></p>