-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to force the width of New-HTMLTable? #469
Comments
I resolved this issue myself and actually improved significantly what I wanted anyway. So, for anyone else wanting to use PSWriteHTML to create email messages with the intent to eliminate the need for HTML expertise, and so HTML is no longer embedded in the script/code... here is the method I found effective:
I no longer use 'New-HTML' as that embeds an enormous amount of javascript and other HTML in order to support an interactive web page. That isn't supported in email; especially, in Outlook so the method I provided above provides clean, limited, HTML that only includes what is necessary to be displayed in an email message (the goal for me). I use 'New-TableHTML' to get the HTML necessary to display an HTML table in the email (no java script, unneeded functions, or unnecessary HTML is included). It's much cleaner. NOTE: The data for the table is a PowerShell array of PSCustomObjects. 'New-HTMLTableHeader' formats the table's column headers. The 'PreContent' section is used to include HTML above the table. To solve my table size option, I replaced text in the output (stored in the '$tableHTML' variable)
NOTE: My problem is that the table width was set to 100% and I found no option to change the table width. The code above replaces 100% with a fixed value of "1000". It could be any value that works including a percentage of the screen width and this works. This is just standard PowerShell to send the HTML as the body of the email message.
Works great. You can see from the code, no HTML expertise is really needed. Just find the raw HTML commands like 'New-HTMLTextbox' in the Public section use what you need. NOTE: Email does not support interactive content, for email, you likely don't need anything more than my example to send HTML formatted messages with color, various fonts and font sizes as well as including formatted data tables. This is what I was after... Simple and easy to automate HTML formatted messages that look professional. |
You're using it wrong... there is dedicated code for email body functionality in PSWriteHTML. Multiple other examples are shown in examples for emails, including on my blog page. If you use it properly it doesnt add javascript and other non working content. |
Email Layout would probably help: |
Okay, if I use EmailBody to format the HTML, how do I prevent the table from spanning the width of the screen (my original question)? Simple example provided:
NOTE/FYI: You will get this message when using "Send-MailMessage -Body" WARNING: The command 'Send-MailMessage' is obsolete. This cmdlet does not guarantee secure connections to SMTP servers. While there is no immediate replacement available in PowerShell, we recommend you do not use Send-MailMessage at this time. See https://aka.ms/SendMailMessage for more information. My example of $SMTPClient.Send($Message) is a better option |
It actually isnt. It uses same .NET code as the obsolete version. Thats why I wrote Mailozaurr module. Your original question - in short its not done, maybe email layout example would work. I havent tested, but it may work. |
Thanks for letting me know setting the table width hasn't been added yet. I was able to use a similar workaround. Here is the modified example: $Table = (Get-Process | Select-Object -First 2 -Property Name, BasePriority, Company, CompanyName) $Body = EmailBody -FontSize 8px -FontFamily 'Tahoma' { Send-MailMessage -Body $Body That allows me to override the table's width and gives me what I need. Thanks NOTE: I left this open because I suspect a lot of users will want setting the table width supported without a workaround. |
I am using PSWriteHTML to format email. When I try New-HTMLTable, it seems the width is ignored and the table is always forced to 100% of the screen width. How do I force the size to less than the full screen width?
I tried:
Neither the New-HTMLPanel resizes the table, nor the ScreenSizePercent parameter for New-HTMLTable.
How do I set the width when the HTML table is in the body of an email (I.e. read in Outlook)? Everything else works.
Thanks
The text was updated successfully, but these errors were encountered: