none
How to add images to the email body of my powershell script. RRS feed

  • General discussion

  • I have a PowerShell script to notify users when there password is about to expire. I would like to imbed these images into the email but I am having a hard time figuring it out. Below is the code and  I would like to embed them after the Paragraph breaks.

    Any help is much appreciated.

    Thanks

    Sincerely

    a PowerShell noob  

     $body ="     
        <p>Dear $name,<br></P><br> 
        <p>Your Password will expire $messageDays.<br> 
        Please change your password before it expires to avoid problems accessing to your work services.<br></P><br>  Press Ctrl-Alt-Del and choose Change Password.
        If you not in a branch connect to the VPN and Press Ctrl-Alt-Del and choose change Password.<br></P><br> 
        If you are working in a terminal server Press Ctrl-Alt-END and Choose Change password.<br></P><br> 
        If you have a mobile device please be sure to update your Password on that device to avoid your account from being locked out.<br></P><br> 
        If you still are having troubles with changing your password please call the help desk at 888-888-8888.  
        <br></P><br> 
        <p>Thanks, <br></P><br> Help Desk <br>
        </P><br><br>" 

    • Changed type Bill_Stewart Tuesday, November 22, 2016 4:22 PM
    • Moved by Bill_Stewart Tuesday, November 22, 2016 4:23 PM This is not "teach me basics of how to construct HTML email messages" forum
    Friday, October 21, 2016 5:23 PM

All replies

  • Thanks, So from what I am getting is I can run a script within a script?
    Friday, October 21, 2016 9:23 PM
  • Yes, you can run a script from within a script.

    -- Bill Stewart [Bill_Stewart]

    Friday, October 21, 2016 9:50 PM
  • Yes, you can run a script from within a script.

    -- Bill Stewart [Bill_Stewart]


    Thanks Bill. Is there a way to add a line of code to add just one image into the body of the email? I already have the mail send settings already set. Now I just want to add an single image after the first paragraph break. Is this possible?

    $body =" <p>Dear $name,<br></P><br> <p>Your Password will expire $messageDays.<br> Please change your password before it expires to avoid problems accessing to your work services.

    <br></P><br>$images = @{ image1 = 'c:\images\email.png } $body = @' <html> <body> <img src="cid:image1"><br> </body> </html> <br></P><br> If you have a mobile device please be sure to update your Password on that device to avoid your account from being locked out.<br></P><br> If you still are having troubles with changing your password please call the help desk at 888-888-8888. <br></P><br> <p>Thanks, <br></P><br> Help Desk <br> </P><br><br>"

    Tuesday, October 25, 2016 2:02 PM
  • Please read the link I posted.  It will explain how to do this.

    You need to add one line to your HTML and attach an image to the "Send-MaiiMessage" along with a declaration of image associations.  The link is a full demo.

    If you do not understand HTML then start here: http://www.w3schools.com/

    <img src="cid:image1"><br> 


    \_(ツ)_/


    • Edited by jrv Tuesday, October 25, 2016 2:21 PM
    Tuesday, October 25, 2016 2:19 PM