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

%3CLINGO-SUB%20id%3D%22lingo-sub-706118%22%20slang%3D%22en-US%22%3EHow%20to%20send%20email%20to%20Microsoft%20Teams%20Channel%20with%20data%20in%20Tabular%20format%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-706118%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3CBR%20%2F%3EI%20have%20attached%20a%20sample%20code%20it%20uses%20HTML%20to%20create%20body%20format%20and%20uses%20sql%20server%3CBR%20%2F%3EDBmail%20to%20send%20notification.%3C%2FP%3E%3CP%3ETabular%20Body%20format%20is%20framing%20properly%20when%20email%20is%20sent%20to%20outlook.%3CBR%20%2F%3EBut%20same%20code%20is%20not%20framing%20the%20table%20format%20when%20i%20send%20email%20to%20MSTeams%20channel.%3CBR%20%2F%3ECan%20any%20one%20let%20me%20know%20how%20to%20get%20the%20same%20tabular%20format%20when%20i%20send%20email%20to%20teams%20channel.%3CBR%20%2F%3EIf%20not%2C%20are%20there%20any%20other%20alternative%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-706118%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-710512%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20send%20email%20to%20Microsoft%20Teams%20Channel%20with%20data%20in%20Tabular%20format%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-710512%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F362806%22%20target%3D%22_blank%22%3E%40DineshPathapati%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20Teams%20channel%20conversation%2C%20hope%20you%20have%20to%20set%20your%20own%20css%20style%20for%20table%20elements.%20Can%20you%20try%20the%20below%20code%20to%20form%20your%20html%20body.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EDECLARE%20%40xml%20NVARCHAR(MAX)%3CBR%20%2F%3EDECLARE%20%40body%20NVARCHAR(MAX)%3CBR%20%2F%3E%3CBR%20%2F%3ESET%20%40xml%20%3D%20CAST((%20SELECT%20%5BFirstName%5D%20AS%20'td'%2C''%2C%5BLastName%5D%20AS%20'td'%2C''%2C%20%5BEmailAddress%5D%20AS%20'td'%3CBR%20%2F%3EFROM%20Person.Contact%20%3CBR%20%2F%3EORDER%20BY%20LastName%2C%20FirstName%20%3CBR%20%2F%3EFOR%20XML%20PATH('tr')%2C%20ELEMENTS%20)%20AS%20NVARCHAR(MAX))%3CBR%20%2F%3E%3CBR%20%2F%3ESET%20%40body%20%3D'%3CBR%20%2F%3E%3CSTYLE%3Etable%20%7B%20border-collapse%3A%20collapse%3B%20%7Dtd%2C%20th%20%7B%20border%3A%201px%20solid%20%23999%3Bpadding%3A%200.5rem%3Btext-align%3A%20left%3B%7D%3C%2FSTYLE%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId-1591393174%22%20id%3D%22toc-hId-1591393174%22%20id%3D%22toc-hId-1591393174%22%20id%3D%22toc-hId-1591393174%22%3EContact%20Info%3C%2FH3%3E%3CBR%20%2F%3E%3CTABLE%3E%20%3CBR%20%2F%3E%3CTBODY%3E%3CTR%3E%3CBR%20%2F%3E%3CTH%3E%20First%20Name%20%3C%2FTH%3E%20%3CTH%3E%20Last%20Name%20%3C%2FTH%3E%20%3CTH%3E%20Email%20%3C%2FTH%3E%3C%2FTR%3E'%20%3CBR%20%2F%3E%3CBR%20%2F%3ESET%20%40body%20%3D%20%40body%20%2B%20%40xml%20%2B'%26lt%3B%2Ftable%26gt%3B%26lt%3B%2Fbody%26gt%3B%26lt%3B%2Fhtml%26gt%3B'%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-713592%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20send%20email%20to%20Microsoft%20Teams%20Channel%20with%20data%20in%20Tabular%20format%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-713592%22%20slang%3D%22en-US%22%3EHi%20Kevin%2C%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20for%20replying.%20I%20have%20changed%20the%20code%20as%20per%20your%20suggestion%20and%20it%20didn't%20changed%20the%20result.%3CBR%20%2F%3EI%20am%20still%20getting%20same%20format%20email%20without%20any%20change.%3CBR%20%2F%3EAny%20further%20suggestions%20on%20this%20please.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-715169%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20send%20email%20to%20Microsoft%20Teams%20Channel%20with%20data%20in%20Tabular%20format%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-715169%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F362806%22%20target%3D%22_blank%22%3E%40DineshPathapati%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EActually%20I%20have%20created%20a%20sample%20table%20in%20new%20teams%20conversation%20post%20(refer%20attached%20image)%20and%20checked%20the%20channel%20conversation%20posts%20from%20Graph%20Explorer%20using%20below%20endpoint.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fbeta%2Fteams%2F%26lt%3Bteam-id%26gt%3B%2Fchannels%2F%26lt%3Bchannel-id%26gt%3B%2Fmessages%3C%2FPRE%3E%3CP%3EReference%20%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fapi%2Fchannel-list-messages%3Fview%3Dgraph-rest-beta%26amp%3Btabs%3Dcs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fapi%2Fchannel-list-messages%3Fview%3Dgraph-rest-beta%26amp%3Btabs%3Dcs%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGot%20the%20below%20html%20content%20for%20the%20table%20post%20%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%22body%22%3A%20%7B%3CBR%20%2F%3E%22contentType%22%3A%20%22html%22%2C%3CBR%20%2F%3E%22content%22%3A%20%22%3CDIV%3E%5Cn%3CTABLE%20itemprop%3D%22%5C%26quot%3Bcopy-paste-block%5C%26quot%3B%22%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3E%5Cn%3CCOLGROUP%3E%3CCOL%20style%3D%22%5C%26quot%3Bwidth%3A33%25%5C%26quot%3B%22%20%2F%3E%3CCOL%20style%3D%22%5C%26quot%3Bwidth%3A33%25%5C%26quot%3B%22%20%2F%3E%3CCOL%20style%3D%22%5C%26quot%3Bwidth%3A33%25%5C%26quot%3B%22%20%2F%3E%3C%2FCOLGROUP%3E%5Cn%3CTBODY%3E%5Cn%3CTR%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3E%5Cn%3CTD%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3ECol1%3C%2FTD%3E%5Cn%3CTD%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3ECol2%3C%2FTD%3E%5Cn%3CTD%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3ECol3%3C%2FTD%3E%5Cn%3C%2FTR%3E%5Cn%3CTR%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3E%5Cn%3CTD%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3Er1c1%3C%2FTD%3E%5Cn%3CTD%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3Er1c2%3C%2FTD%3E%5Cn%3CTD%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3Er1c3%3C%2FTD%3E%5Cn%3C%2FTR%3E%5Cn%3CTR%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3E%5Cn%3CTD%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3Er2c1%3C%2FTD%3E%5Cn%3CTD%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3Er2c2%3C%2FTD%3E%5Cn%3CTD%20style%3D%22%5C%26quot%3Bborder-width%3A1px%3B%22%20solid%3D%22%22%3Er2c3%3C%2FTD%3E%5Cn%3C%2FTR%3E%5Cn%3C%2FTBODY%3E%5Cn%3C%2FTABLE%3E%5Cn%5Cn%5Cn%5Cn%3C%2FDIV%3E%22%3CBR%20%2F%3E%7D%2C%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20you%20can%20see%20every%20table%20elements%20(table%2C%20tr%2C%20td)%20have%20their%20own%20implicit%20style...So%20hope%20you%20have%20to%20set%20implicit%20style%20for%20every%20element%20of%20the%20table.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1254186%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20send%20email%20to%20Microsoft%20Teams%20Channel%20with%20data%20in%20Tabular%20format%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1254186%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F362806%22%20target%3D%22_blank%22%3E%40DineshPathapati%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20you%20solved%20your%20problem%20with%20html%20email%20send%20to%20Teams%20Channel%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20also%20have%20this%20problem%20with%20table%20in%20teams%20channel.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEric%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New 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
Highlighted

@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>'
Highlighted
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.
Highlighted

@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.

Highlighted

@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