Actually I am having the Shift Handover file in which Sheet 1 needs to be send mail automatically through Powershell.I am using this to send the excel sheet in the mail but I need to insert the image in body before excel sheet which is not happening.Kindly help me on this
There are a number of examples on the web on how to do this. NO reason to do this from scratch except as a learning effort. Even then, leveraging existing working code as part of the learning process is still prudent.
Using you posts’ title in any search engine will reveal a number of code blocks you can download and tweak as needed.
For example:
Send-MailMessage function with support for inline attachments
Embed inline attachments into HTML bodies with a new Send-MailMessage function.
The Send-MailMessage cmdlet exposes most of the basic functionality for sending email, but you don’t get a lot of control over things like attachments or alternate views. Someone on the TechNet forums was asking how to embed images into an HTML mail message, and I decided to write a version of Send-MailMessage that supports this. I started with a proxy function for the Send-MailMessage cmdlet, so all of the parameters and usage should be intact. The main difference is that I added an -InlineAttachments argument, which accepts a hashtable of pairs in the format ‘ContentId’='FilePath. You can then embed the resources into an HTML body by using URLs of the format “cid:ContentId”.
Born from a need to send something better then plain text emails, this script allows for rich email content, as well as including inline attached images (which means Outlook will display them by default
internally, and won’t nag about security.)
Send Email with images in PowerShell
'sharepointfire.com/2011/12/send-email-with-images-in-powershell'
How to embed Images in a powershell email using MailMessage
'stackoverflow.com/questions/29237687/how-to-embed-images-in-a-powershell-email-using-mailmessage'
(PowerShell) Embed Image in HTML Email
'example-code.com/powershell/smtp_EmbedImage.asp'
I have got this script which is working where i need to select with Range where the hidden formulas are present inside the excel so only ranges needs to selected how to do this ?I need to add hyperlink for the Introduction which is not happening?
$xl=New-Object -ComObject Excel.Application
$wb=$xl.Workbooks.Open(‘c:\scripts\process.xlsx’)
$ws=$wb.Sheets.Item(1)
$ws.MailEnvelope.Introduction = “This is a sample worksheet.”
$ws.MailEnvelope.Item.To = “recipient@domain.com”
$ws.MailEnvelope.Item.Subject = “My subject”
$ws.MailEnvelope.Item.Send()
As-is, I don’t see where you’re producing valid HTML in the first place. How is $ForEmail getting HTML in it?
Also, your Body string is not really well-formed. If you’re using -BodyAsHTML, then the ENTIRE BODY needs to be HTML, which means it needs to start with HTML. Yours does not; it starts with “Here is the contents of the excel file,” which is not HTML. As a test, ensure that $ForEmail contains valid HTML, and then set Body = $ForEmail with no other text.
Also, since you’re being very pushy in asking for help on this, please at least take the time to format your code in your posts, as clearly explained in the bullet list above the posting text box. Thank you.