How to send email to Microsoft Teams Channel with data in Tabular format

Copper Contributor

Hi
I have attached a sample code it uses HTML to create body format and uses sql server
DBmail to send notification.

Tabular Body format is framing properly when email is sent to outlook.
But same code is not framing the table format when i send email to MSTeams channel.
Can any one let me know how to get the same tabular format when i send email to teams channel.
If not, are there any other alternative?

4 Replies

@DineshPathapati 

 

For Teams channel conversation, hope you have to set your own css style for table elements. Can you try the below code to form your html body.

 

DECLARE @xml NVARCHAR(MAX)
DECLARE @body NVARCHAR(MAX)

SET @xml = CAST(( SELECT [FirstName] AS 'td','',[LastName] AS 'td','', [EmailAddress] AS 'td'
FROM Person.Contact
ORDER BY LastName, FirstName
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))

SET @body ='<html>
<style>table { border-collapse: collapse; }td, th { border: 1px solid #999;padding: 0.5rem;text-align: left;}</style>
<body><H3>Contact Info</H3>
<table>
<tr>
<th> First Name </th> <th> Last Name </th> <th> Email </th></tr>'

SET @body = @body + @xml +'</table></body></html>'
Hi Kevin,

Thank you for replying. I have changed the code as per your suggestion and it didn't changed the result.
I am still getting same format email without any change.
Any further suggestions on this please.

@DineshPathapati 

 

Actually I have created a sample table in new teams conversation post (refer attached image) and checked the channel conversation posts from Graph Explorer using below endpoint.

 

https://graph.microsoft.com/beta/teams/<team-id>/channels/<channel-id>/messages

Reference : https://docs.microsoft.com/en-us/graph/api/channel-list-messages?view=graph-rest-beta&tabs=cs

 

Got the below html content for the table post :

 

"body": {
"contentType": "html",
"content": "<div>\n<table itemprop=\"copy-paste-block\" style=\"border-width:1px; border-style:solid; width:100%\">\n<colgroup><col style=\"width:33%\"><col style=\"width:33%\"><col style=\"width:33%\"></colgroup>\n<tbody>\n<tr style=\"border-width:1px; border-style:solid\">\n<td style=\"border-width:1px; border-style:solid; padding:0.3rem 0.6rem\">Col1</td>\n<td style=\"border-width:1px; border-style:solid; padding:0.3rem 0.6rem\">Col2</td>\n<td style=\"border-width:1px; border-style:solid; padding:0.3rem 0.6rem\">Col3</td>\n</tr>\n<tr style=\"border-width:1px; border-style:solid\">\n<td style=\"border-width:1px; border-style:solid; padding:0.3rem 0.6rem\">r1c1</td>\n<td style=\"border-width:1px; border-style:solid; padding:0.3rem 0.6rem\">r1c2</td>\n<td style=\"border-width:1px; border-style:solid; padding:0.3rem 0.6rem\">r1c3</td>\n</tr>\n<tr style=\"border-width:1px; border-style:solid\">\n<td style=\"border-width:1px; border-style:solid; padding:0.3rem 0.6rem\">r2c1</td>\n<td style=\"border-width:1px; border-style:solid; padding:0.3rem 0.6rem\">r2c2</td>\n<td style=\"border-width:1px; border-style:solid; padding:0.3rem 0.6rem\">r2c3</td>\n</tr>\n</tbody>\n</table>\n\n\n\n</div>"
},

 

Here you can see every table elements (table, tr, td) have their own implicit style...So hope you have to set implicit style for every element of the table.

@DineshPathapati 

 

Do you solved your problem with html email send to Teams Channel?

 

I also have this problem with table in teams channel.

 

Regards,

 

Eric