Built-in html powershell email compressing pic length

I have a powershell script that embeds (doesn't attach) an image and sends an email. Now the picture has increased to 1500x5000 pixels, and now I see that lenth photos are compressed and distort the image. Be that as it may, when I manually insert a picture through Outlook and send an email, it looks good.

If I save the image and then open it with paint or something else, the image will open perfectly. It just looks concise in the letter. Does anyone know what can happen there?

{ $Application = "C:\Autobatch\Spotfire.Dxp.Automation.ClientJobSender.exe" $Arguments = "http://s.net:8070/spotfireautomation/JobExecutor.asmx C:\Autobatch\HourlyStats.xml" $CommandLine = "{0} {1}" -f $Application,$Arguments invoke-expression $CommandLine $file = "C:\Autobatch\HourlyStats.png" $smtpServer = "smtp.staom.sec.s.net" $att = new-object Net.Mail.Attachment($file) $att.ContentType.MediaType = "image/png" $att.ContentId = "pict" $att.TransferEncoding = [System.Net.Mime.TransferEncoding]::Base64 $msg = new-object Net.Mail.MailMessage $smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.Attachments.Add($att) $msg.From = " d.k@s.com " $msg.To.Add(" r.p@p.com ") $msg.Subject = "Voice and Data Hourly Stats" $msg.Body = "<p style='font-family: Calibri, sans-serif'> Voice and data hourly stats details<br /> </p> <img src='cid:pict'/>" $msg.IsBodyHTML = $true $smtp.Send($msg) $att.Dispose() invoke-expression "DEL $file" } 

this is what the image looks like in the letter. compressed pic

+4
source share
4 answers

Try to add

 $att.ContentDisposition.Inline = $true 

I suspect that some kind of default behavior occurs under the covers, and it just does not agree between script and Outlook.

More here

+2
source

It seems that your email client compresses the content to a certain maximum size. Try putting <img src='cid:pict'/> in the <div> environment:

 <div style="overflow: scroll"> <img src='cid:pict'/> </div> 

Also, if you have any way to get the actual width of the image pixel, you can try setting the CSS of the <img> accordingly.

+2
source

I ask about this, I can be like noob, but just out of curiosity, if you have a manual way to send emails via Outlook, why not make a script to send an automated email with the desired screenshot?

IDK, if this can help you or not, but I made this script a long back, for daily reporting. Well, that matches the bill. Share it here to look at it.

 #In this segment, I navigate IE to my specific destination, screen which I want to capture. $ie = New-Object -ComObject InternetExplorer.Application $ie.Visible = $true; $Website = $ie.navigate('https://put.your.URL.here') while($Website.Busy){Start-Sleep -Seconds 5} #In this class, script captures the screen, once, all the data loading is over. $file = "C:\Users\Desktop\$(Get-Date -Format dd-MM-yyyy-hhmm).bmp" #PS I made it to save that screenshot with current date and time format. Also, default screenshot will be captured in .BMP format. Add-Type -AssemblyName System.Windows.Forms Add-type -AssemblyName System.Drawing $Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen $width = $Screen.width $Height = $Screen.Height $Left = $Screen.Left $Right = $Screen.Right $Top = $Screen.Top $Bottom = $Screen.Bottom $bitmap = New-Object System.Drawing.Bitmap $width, $Height $Graphics = [System.Drawing.Graphics]::FromImage($bitmap) $Graphics.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size) $bitmap.Save($File) Write-Output "Screenshot saved to:" Write-Output $File sleep -Seconds 5 #Sending an Email $Outlook = New-Object -ComObject Outlook.Application $mail = $Outlook.CreateItem(0) $mail.To = " your.designated@emailid.com " $mail.Subject = "Outstanding data as on $(Get-Date -Format dd-MM-yyyy)" $mail.Body = "PFA screenshot, of all outstanding formation as on $(Get-Date -Format dd-MM-yyyy-hhmm)" $mail.Attachments.Add($file) $mail.Send() 

I just answer this since I tried to comment above, but I think my reputation rating is too low to do so. Hope this can be helpful for you to find a workaround. Happy coding. :)

0
source

HTML code: <img src='cid:pict'/> should be <img src='cid:pict'> - just remove the slash?

Added: This link can help to talk about embedding pic in email. base64 encoded images in email signatures . You can try to generate base64 code and put it in the HTML email address.

-2
source

Source: https://habr.com/ru/post/1490361/


All Articles