0

I am using below script for sending a mail.

{

$imgfile = “C:\Users\Rammy\Desktop\Pic.png”
$SMTPServer = “smtp.gmail.com”
$SMTPPort = “587”
$Username = “motheramesh486@gmail.com”
$Password = “xxxxxxxx”

$to = “motheramesh486@gmail.com”
$cc = “motheramesh486@gmail.com”
$subject = “Email Subject”
$body = @”
<html>
<body>
<img src="cid:image1.png">
</body>
</html>
“@

$attachment = New-Object System.Net.Mail.Attachment($imgfile)

$attachment.ContentDisposition.Inline = $True
$attachment.ContentDisposition.DispositionType = “Inline”
$attachment.ContentType.MediaType = “image/png”
$attachment.ContentId = ‘image1.png’

$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.IsBodyHtml = $True

$message.body = $body
$message.to.add($to)
$message.cc.add($cc)
$message.from = $username
$message.attachments.add($attachment)

$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username,         $Password);

$smtp.send($message)
write-host “Mail Sent”

$attachment.Dispose();
$message.Dispose();
}

I am able to send the mail using above script but it compressed pic length. The picture has 1500x5000 pixels and now I'm seeing that the pictures length gets compressed and it distorts the picture. How ever, when I manually insert the picture via outlook and send an email, it looks absolutely fine.

If i save the picture and then open it via paint or something, the picture opens fine. It just looks compressed in the email. Anyone know what may be going on there?

Click here to see how the image looks like in mail

Click here for original image

0 Answers0