Powershell Sent the email with HTML table in the message body












0















The email I sent contain HTML table.



The html table saved in the $MailBody



$MailBody = @{<!DOCTYPE html>
<html>
<head>
<style>
#customers {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

#customers td, #customers th {
border: 1px solid #ddd;
padding: 8px;
}

#customers tr:nth-child(even){background-color: #f2f2f2;}

#customers tr:hover {background-color: #ddd;}

#customers th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>

<table id="customers">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbköp</td>
<td>Christina Berglund</td>
<td>Sweden</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Königlich Essen</td>
<td>Philip Cramer</td>
<td>Germany</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>North/South</td>
<td>Simon Crowther</td>
<td>UK</td>
</tr>
<tr>
<td>Paris spécialités</td>
<td>Marie Bertrand</td>
<td>France</td>
</tr>
</table>

</body>
</html>
}


This is the code for sending the email along with the HTML table



$Msg = @{
to = ($MailtTo -split ';')
from = $MailFrom
BodyAsHtml = $True
Subject = $MailSubject
Body = $MailBody
smtpserver = $SmtpServer
Credential = $Credentials
}

Send-MailMessage @Msg


I found that the view of the table from Window Outlook is different from the Web Browser Outlook.



All the HTML table column are shrink in Window Outlook.



I wish to view the HTML table in the Window Outlook same as it looks from HTML



Is there any solution to solve this problem ?










share|improve this question

























  • This has nothing to do with Powershell and everything to do with how the HTML is rendered. I've edited the tags accordingly.

    – alroc
    Nov 23 '18 at 2:18











  • @alroc But the html code when I save into html file and open it at browser it show perfectly as I want to. Only when I open in the Window Outlook all the column are shrink.

    – Jack Lim
    Nov 23 '18 at 2:34
















0















The email I sent contain HTML table.



The html table saved in the $MailBody



$MailBody = @{<!DOCTYPE html>
<html>
<head>
<style>
#customers {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

#customers td, #customers th {
border: 1px solid #ddd;
padding: 8px;
}

#customers tr:nth-child(even){background-color: #f2f2f2;}

#customers tr:hover {background-color: #ddd;}

#customers th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>

<table id="customers">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbköp</td>
<td>Christina Berglund</td>
<td>Sweden</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Königlich Essen</td>
<td>Philip Cramer</td>
<td>Germany</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>North/South</td>
<td>Simon Crowther</td>
<td>UK</td>
</tr>
<tr>
<td>Paris spécialités</td>
<td>Marie Bertrand</td>
<td>France</td>
</tr>
</table>

</body>
</html>
}


This is the code for sending the email along with the HTML table



$Msg = @{
to = ($MailtTo -split ';')
from = $MailFrom
BodyAsHtml = $True
Subject = $MailSubject
Body = $MailBody
smtpserver = $SmtpServer
Credential = $Credentials
}

Send-MailMessage @Msg


I found that the view of the table from Window Outlook is different from the Web Browser Outlook.



All the HTML table column are shrink in Window Outlook.



I wish to view the HTML table in the Window Outlook same as it looks from HTML



Is there any solution to solve this problem ?










share|improve this question

























  • This has nothing to do with Powershell and everything to do with how the HTML is rendered. I've edited the tags accordingly.

    – alroc
    Nov 23 '18 at 2:18











  • @alroc But the html code when I save into html file and open it at browser it show perfectly as I want to. Only when I open in the Window Outlook all the column are shrink.

    – Jack Lim
    Nov 23 '18 at 2:34














0












0








0








The email I sent contain HTML table.



The html table saved in the $MailBody



$MailBody = @{<!DOCTYPE html>
<html>
<head>
<style>
#customers {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

#customers td, #customers th {
border: 1px solid #ddd;
padding: 8px;
}

#customers tr:nth-child(even){background-color: #f2f2f2;}

#customers tr:hover {background-color: #ddd;}

#customers th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>

<table id="customers">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbköp</td>
<td>Christina Berglund</td>
<td>Sweden</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Königlich Essen</td>
<td>Philip Cramer</td>
<td>Germany</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>North/South</td>
<td>Simon Crowther</td>
<td>UK</td>
</tr>
<tr>
<td>Paris spécialités</td>
<td>Marie Bertrand</td>
<td>France</td>
</tr>
</table>

</body>
</html>
}


This is the code for sending the email along with the HTML table



$Msg = @{
to = ($MailtTo -split ';')
from = $MailFrom
BodyAsHtml = $True
Subject = $MailSubject
Body = $MailBody
smtpserver = $SmtpServer
Credential = $Credentials
}

Send-MailMessage @Msg


I found that the view of the table from Window Outlook is different from the Web Browser Outlook.



All the HTML table column are shrink in Window Outlook.



I wish to view the HTML table in the Window Outlook same as it looks from HTML



Is there any solution to solve this problem ?










share|improve this question
















The email I sent contain HTML table.



The html table saved in the $MailBody



$MailBody = @{<!DOCTYPE html>
<html>
<head>
<style>
#customers {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

#customers td, #customers th {
border: 1px solid #ddd;
padding: 8px;
}

#customers tr:nth-child(even){background-color: #f2f2f2;}

#customers tr:hover {background-color: #ddd;}

#customers th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>

<table id="customers">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbköp</td>
<td>Christina Berglund</td>
<td>Sweden</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Königlich Essen</td>
<td>Philip Cramer</td>
<td>Germany</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>North/South</td>
<td>Simon Crowther</td>
<td>UK</td>
</tr>
<tr>
<td>Paris spécialités</td>
<td>Marie Bertrand</td>
<td>France</td>
</tr>
</table>

</body>
</html>
}


This is the code for sending the email along with the HTML table



$Msg = @{
to = ($MailtTo -split ';')
from = $MailFrom
BodyAsHtml = $True
Subject = $MailSubject
Body = $MailBody
smtpserver = $SmtpServer
Credential = $Credentials
}

Send-MailMessage @Msg


I found that the view of the table from Window Outlook is different from the Web Browser Outlook.



All the HTML table column are shrink in Window Outlook.



I wish to view the HTML table in the Window Outlook same as it looks from HTML



Is there any solution to solve this problem ?







html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 2:17









alroc

23.2k33465




23.2k33465










asked Nov 23 '18 at 2:09









Jack LimJack Lim

478




478













  • This has nothing to do with Powershell and everything to do with how the HTML is rendered. I've edited the tags accordingly.

    – alroc
    Nov 23 '18 at 2:18











  • @alroc But the html code when I save into html file and open it at browser it show perfectly as I want to. Only when I open in the Window Outlook all the column are shrink.

    – Jack Lim
    Nov 23 '18 at 2:34



















  • This has nothing to do with Powershell and everything to do with how the HTML is rendered. I've edited the tags accordingly.

    – alroc
    Nov 23 '18 at 2:18











  • @alroc But the html code when I save into html file and open it at browser it show perfectly as I want to. Only when I open in the Window Outlook all the column are shrink.

    – Jack Lim
    Nov 23 '18 at 2:34

















This has nothing to do with Powershell and everything to do with how the HTML is rendered. I've edited the tags accordingly.

– alroc
Nov 23 '18 at 2:18





This has nothing to do with Powershell and everything to do with how the HTML is rendered. I've edited the tags accordingly.

– alroc
Nov 23 '18 at 2:18













@alroc But the html code when I save into html file and open it at browser it show perfectly as I want to. Only when I open in the Window Outlook all the column are shrink.

– Jack Lim
Nov 23 '18 at 2:34





@alroc But the html code when I save into html file and open it at browser it show perfectly as I want to. Only when I open in the Window Outlook all the column are shrink.

– Jack Lim
Nov 23 '18 at 2:34












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439880%2fpowershell-sent-the-email-with-html-table-in-the-message-body%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439880%2fpowershell-sent-the-email-with-html-table-in-the-message-body%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy