Email with inline attachments using powershell



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Requirement:



Send a mail with inline image with out attaching the image as attachment using powershell.



My Powershell Code:



$From = "From@gmail.com"
$ToEmails = "ToEmails@gmail.com"
$CcEmails = "CcEmails@gmail.com"
$userName = "From@gmail.com"
$ImageName = "codecover.png"
$FilePath = "D:$($ImageName)"
$Attachment = @($FilePath)
$Subject = "Test Subject"
$password = "From Email password"
$SMTPServer = "smtp.outlook.com"
$SMTPPort = "587"
$Body += "<img src='$($ImageName)' />"

[string][ValidateNotNullOrEmpty()]$password = $password
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$Credentials = New-Object Management.Automation.PSCredential ($userName, $securePassword)

Send-MailMessage -From $From -to $ToEmails -Cc $CcEmails -Subject $Subject -BodyAsHtml -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Credentials -Attachments $Attachment –DeliveryNotificationOption OnSuccess


Problem with my Result:



Result of the mail sending with inline attachment but the same image is in attachments which i dont want. Please find the screen shot below



enter image description here



Please suggest me how to send the inline images without attaching that image in attachments.










share|improve this question
























  • Remove " -Attachments $Attachment" from the Send-MailMessage and you're good to go!

    – Bernard Moeskops
    Nov 16 '18 at 12:00











  • Hi @BernardMoeskops, if i remove the attachment parameter, the inline image is also not displaying.

    – Chandramouli
    Nov 16 '18 at 12:12











  • Possible duplicate of How to embed Images in a powershell email using MailMessage

    – LotPings
    Nov 16 '18 at 12:18











  • Weird, I tested it from Gmail to Outlook and it worked. Seems it is only not working in Gmail..

    – Bernard Moeskops
    Nov 16 '18 at 12:26











  • Found it, Google only allows images which are coming from a trusted source. Therefore if you would store the images in for instance Google Drive it works..

    – Bernard Moeskops
    Nov 16 '18 at 12:34

















0















Requirement:



Send a mail with inline image with out attaching the image as attachment using powershell.



My Powershell Code:



$From = "From@gmail.com"
$ToEmails = "ToEmails@gmail.com"
$CcEmails = "CcEmails@gmail.com"
$userName = "From@gmail.com"
$ImageName = "codecover.png"
$FilePath = "D:$($ImageName)"
$Attachment = @($FilePath)
$Subject = "Test Subject"
$password = "From Email password"
$SMTPServer = "smtp.outlook.com"
$SMTPPort = "587"
$Body += "<img src='$($ImageName)' />"

[string][ValidateNotNullOrEmpty()]$password = $password
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$Credentials = New-Object Management.Automation.PSCredential ($userName, $securePassword)

Send-MailMessage -From $From -to $ToEmails -Cc $CcEmails -Subject $Subject -BodyAsHtml -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Credentials -Attachments $Attachment –DeliveryNotificationOption OnSuccess


Problem with my Result:



Result of the mail sending with inline attachment but the same image is in attachments which i dont want. Please find the screen shot below



enter image description here



Please suggest me how to send the inline images without attaching that image in attachments.










share|improve this question
























  • Remove " -Attachments $Attachment" from the Send-MailMessage and you're good to go!

    – Bernard Moeskops
    Nov 16 '18 at 12:00











  • Hi @BernardMoeskops, if i remove the attachment parameter, the inline image is also not displaying.

    – Chandramouli
    Nov 16 '18 at 12:12











  • Possible duplicate of How to embed Images in a powershell email using MailMessage

    – LotPings
    Nov 16 '18 at 12:18











  • Weird, I tested it from Gmail to Outlook and it worked. Seems it is only not working in Gmail..

    – Bernard Moeskops
    Nov 16 '18 at 12:26











  • Found it, Google only allows images which are coming from a trusted source. Therefore if you would store the images in for instance Google Drive it works..

    – Bernard Moeskops
    Nov 16 '18 at 12:34













0












0








0


2






Requirement:



Send a mail with inline image with out attaching the image as attachment using powershell.



My Powershell Code:



$From = "From@gmail.com"
$ToEmails = "ToEmails@gmail.com"
$CcEmails = "CcEmails@gmail.com"
$userName = "From@gmail.com"
$ImageName = "codecover.png"
$FilePath = "D:$($ImageName)"
$Attachment = @($FilePath)
$Subject = "Test Subject"
$password = "From Email password"
$SMTPServer = "smtp.outlook.com"
$SMTPPort = "587"
$Body += "<img src='$($ImageName)' />"

[string][ValidateNotNullOrEmpty()]$password = $password
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$Credentials = New-Object Management.Automation.PSCredential ($userName, $securePassword)

Send-MailMessage -From $From -to $ToEmails -Cc $CcEmails -Subject $Subject -BodyAsHtml -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Credentials -Attachments $Attachment –DeliveryNotificationOption OnSuccess


Problem with my Result:



Result of the mail sending with inline attachment but the same image is in attachments which i dont want. Please find the screen shot below



enter image description here



Please suggest me how to send the inline images without attaching that image in attachments.










share|improve this question
















Requirement:



Send a mail with inline image with out attaching the image as attachment using powershell.



My Powershell Code:



$From = "From@gmail.com"
$ToEmails = "ToEmails@gmail.com"
$CcEmails = "CcEmails@gmail.com"
$userName = "From@gmail.com"
$ImageName = "codecover.png"
$FilePath = "D:$($ImageName)"
$Attachment = @($FilePath)
$Subject = "Test Subject"
$password = "From Email password"
$SMTPServer = "smtp.outlook.com"
$SMTPPort = "587"
$Body += "<img src='$($ImageName)' />"

[string][ValidateNotNullOrEmpty()]$password = $password
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$Credentials = New-Object Management.Automation.PSCredential ($userName, $securePassword)

Send-MailMessage -From $From -to $ToEmails -Cc $CcEmails -Subject $Subject -BodyAsHtml -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Credentials -Attachments $Attachment –DeliveryNotificationOption OnSuccess


Problem with my Result:



Result of the mail sending with inline attachment but the same image is in attachments which i dont want. Please find the screen shot below



enter image description here



Please suggest me how to send the inline images without attaching that image in attachments.







powershell email






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 12:15







Chandramouli

















asked Nov 16 '18 at 11:46









ChandramouliChandramouli

10318




10318












  • Remove " -Attachments $Attachment" from the Send-MailMessage and you're good to go!

    – Bernard Moeskops
    Nov 16 '18 at 12:00











  • Hi @BernardMoeskops, if i remove the attachment parameter, the inline image is also not displaying.

    – Chandramouli
    Nov 16 '18 at 12:12











  • Possible duplicate of How to embed Images in a powershell email using MailMessage

    – LotPings
    Nov 16 '18 at 12:18











  • Weird, I tested it from Gmail to Outlook and it worked. Seems it is only not working in Gmail..

    – Bernard Moeskops
    Nov 16 '18 at 12:26











  • Found it, Google only allows images which are coming from a trusted source. Therefore if you would store the images in for instance Google Drive it works..

    – Bernard Moeskops
    Nov 16 '18 at 12:34

















  • Remove " -Attachments $Attachment" from the Send-MailMessage and you're good to go!

    – Bernard Moeskops
    Nov 16 '18 at 12:00











  • Hi @BernardMoeskops, if i remove the attachment parameter, the inline image is also not displaying.

    – Chandramouli
    Nov 16 '18 at 12:12











  • Possible duplicate of How to embed Images in a powershell email using MailMessage

    – LotPings
    Nov 16 '18 at 12:18











  • Weird, I tested it from Gmail to Outlook and it worked. Seems it is only not working in Gmail..

    – Bernard Moeskops
    Nov 16 '18 at 12:26











  • Found it, Google only allows images which are coming from a trusted source. Therefore if you would store the images in for instance Google Drive it works..

    – Bernard Moeskops
    Nov 16 '18 at 12:34
















Remove " -Attachments $Attachment" from the Send-MailMessage and you're good to go!

– Bernard Moeskops
Nov 16 '18 at 12:00





Remove " -Attachments $Attachment" from the Send-MailMessage and you're good to go!

– Bernard Moeskops
Nov 16 '18 at 12:00













Hi @BernardMoeskops, if i remove the attachment parameter, the inline image is also not displaying.

– Chandramouli
Nov 16 '18 at 12:12





Hi @BernardMoeskops, if i remove the attachment parameter, the inline image is also not displaying.

– Chandramouli
Nov 16 '18 at 12:12













Possible duplicate of How to embed Images in a powershell email using MailMessage

– LotPings
Nov 16 '18 at 12:18





Possible duplicate of How to embed Images in a powershell email using MailMessage

– LotPings
Nov 16 '18 at 12:18













Weird, I tested it from Gmail to Outlook and it worked. Seems it is only not working in Gmail..

– Bernard Moeskops
Nov 16 '18 at 12:26





Weird, I tested it from Gmail to Outlook and it worked. Seems it is only not working in Gmail..

– Bernard Moeskops
Nov 16 '18 at 12:26













Found it, Google only allows images which are coming from a trusted source. Therefore if you would store the images in for instance Google Drive it works..

– Bernard Moeskops
Nov 16 '18 at 12:34





Found it, Google only allows images which are coming from a trusted source. Therefore if you would store the images in for instance Google Drive it works..

– Bernard Moeskops
Nov 16 '18 at 12:34












1 Answer
1






active

oldest

votes


















1














You can have it base64 encoded.



$Byte = [system.io.file]::ReadAllBytes("C:yourImage.png")
$Base64 = [System.Convert]::ToBase64String($Byte)
$Content = '012' -f '<img src="data:image/png;base64,',$Base64,'">'


Use the content as the message Body.






share|improve this answer























  • Thank you for the Answer i think this idea will work. But i have one issue with this. When i send the $Content as my body i'm not getting image in mail. When i check with inspect element i could see like this "<img data-imagetype="Empty" data-imageerror="SrcNullOrEmpty" originalsrc="" src="">". But when i copy pasted the $Content in a web page for checking it is displaing my image perfectly. Can you please suggest why $content is not matched with the image tag in mail. Whether i need to use any content types in mail like. Please suggest

    – Chandramouli
    Nov 17 '18 at 14:01












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%2f53337254%2femail-with-inline-attachments-using-powershell%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can have it base64 encoded.



$Byte = [system.io.file]::ReadAllBytes("C:yourImage.png")
$Base64 = [System.Convert]::ToBase64String($Byte)
$Content = '012' -f '<img src="data:image/png;base64,',$Base64,'">'


Use the content as the message Body.






share|improve this answer























  • Thank you for the Answer i think this idea will work. But i have one issue with this. When i send the $Content as my body i'm not getting image in mail. When i check with inspect element i could see like this "<img data-imagetype="Empty" data-imageerror="SrcNullOrEmpty" originalsrc="" src="">". But when i copy pasted the $Content in a web page for checking it is displaing my image perfectly. Can you please suggest why $content is not matched with the image tag in mail. Whether i need to use any content types in mail like. Please suggest

    – Chandramouli
    Nov 17 '18 at 14:01
















1














You can have it base64 encoded.



$Byte = [system.io.file]::ReadAllBytes("C:yourImage.png")
$Base64 = [System.Convert]::ToBase64String($Byte)
$Content = '012' -f '<img src="data:image/png;base64,',$Base64,'">'


Use the content as the message Body.






share|improve this answer























  • Thank you for the Answer i think this idea will work. But i have one issue with this. When i send the $Content as my body i'm not getting image in mail. When i check with inspect element i could see like this "<img data-imagetype="Empty" data-imageerror="SrcNullOrEmpty" originalsrc="" src="">". But when i copy pasted the $Content in a web page for checking it is displaing my image perfectly. Can you please suggest why $content is not matched with the image tag in mail. Whether i need to use any content types in mail like. Please suggest

    – Chandramouli
    Nov 17 '18 at 14:01














1












1








1







You can have it base64 encoded.



$Byte = [system.io.file]::ReadAllBytes("C:yourImage.png")
$Base64 = [System.Convert]::ToBase64String($Byte)
$Content = '012' -f '<img src="data:image/png;base64,',$Base64,'">'


Use the content as the message Body.






share|improve this answer













You can have it base64 encoded.



$Byte = [system.io.file]::ReadAllBytes("C:yourImage.png")
$Base64 = [System.Convert]::ToBase64String($Byte)
$Content = '012' -f '<img src="data:image/png;base64,',$Base64,'">'


Use the content as the message Body.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 15:55









Prasoon Karunan VPrasoon Karunan V

1,8942722




1,8942722












  • Thank you for the Answer i think this idea will work. But i have one issue with this. When i send the $Content as my body i'm not getting image in mail. When i check with inspect element i could see like this "<img data-imagetype="Empty" data-imageerror="SrcNullOrEmpty" originalsrc="" src="">". But when i copy pasted the $Content in a web page for checking it is displaing my image perfectly. Can you please suggest why $content is not matched with the image tag in mail. Whether i need to use any content types in mail like. Please suggest

    – Chandramouli
    Nov 17 '18 at 14:01


















  • Thank you for the Answer i think this idea will work. But i have one issue with this. When i send the $Content as my body i'm not getting image in mail. When i check with inspect element i could see like this "<img data-imagetype="Empty" data-imageerror="SrcNullOrEmpty" originalsrc="" src="">". But when i copy pasted the $Content in a web page for checking it is displaing my image perfectly. Can you please suggest why $content is not matched with the image tag in mail. Whether i need to use any content types in mail like. Please suggest

    – Chandramouli
    Nov 17 '18 at 14:01

















Thank you for the Answer i think this idea will work. But i have one issue with this. When i send the $Content as my body i'm not getting image in mail. When i check with inspect element i could see like this "<img data-imagetype="Empty" data-imageerror="SrcNullOrEmpty" originalsrc="" src="">". But when i copy pasted the $Content in a web page for checking it is displaing my image perfectly. Can you please suggest why $content is not matched with the image tag in mail. Whether i need to use any content types in mail like. Please suggest

– Chandramouli
Nov 17 '18 at 14:01






Thank you for the Answer i think this idea will work. But i have one issue with this. When i send the $Content as my body i'm not getting image in mail. When i check with inspect element i could see like this "<img data-imagetype="Empty" data-imageerror="SrcNullOrEmpty" originalsrc="" src="">". But when i copy pasted the $Content in a web page for checking it is displaing my image perfectly. Can you please suggest why $content is not matched with the image tag in mail. Whether i need to use any content types in mail like. Please suggest

– Chandramouli
Nov 17 '18 at 14:01




















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%2f53337254%2femail-with-inline-attachments-using-powershell%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

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線