sirbounty
asked on
Reproducing an html email
I'm running a powershell script that accumulates some reporting data.
Within the current method, is a copy/paste solution from an internal web page. This copy includes a single image - a graphical represenation of a failure.
I have the link to the image, and if I paste my html code into a file, save it as html, it renders fine.
However, if I do this from within powershell, using the send-mailmessage cmdlet with -bodyashtml, it fails to bring in the image - I get a blank box instead.
How can I reproduce this in my email?
Within the current method, is a copy/paste solution from an internal web page. This copy includes a single image - a graphical represenation of a failure.
I have the link to the image, and if I paste my html code into a file, save it as html, it renders fine.
However, if I do this from within powershell, using the send-mailmessage cmdlet with -bodyashtml, it fails to bring in the image - I get a blank box instead.
How can I reproduce this in my email?
ASKER
Trying to automate a solution here, so manually copying the image won't work.
I've tried including the img locally to the server and pointing to it there (not a web server).
I've also tried pointing the img source to a web server where the image is stored.
If I take my generated html script and paste it into a text file, everything appears as I desire, but sending it via email does not.
I've tried including the img locally to the server and pointing to it there (not a web server).
I've also tried pointing the img source to a web server where the image is stored.
If I take my generated html script and paste it into a text file, everything appears as I desire, but sending it via email does not.
ASKER
Actually opening the email, viewing the source, and pasting that info in a test.html file works as well...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No, the email is not okay. The source from the email renders fine if run outside of the email client (Outlook).
I think this is what I need: http://social.technet.microsoft.com/Forums/scriptcenter/en-US/1d9c7094-6991-4027-b7e2-d447d72dfec4/embed-a-background-image-in-a-html-code-sent-via-powershell
I'm just trying to get it working...
I think this is what I need: http://social.technet.microsoft.com/Forums/scriptcenter/en-US/1d9c7094-6991-4027-b7e2-d447d72dfec4/embed-a-background-image-in-a-html-code-sent-via-powershell
I'm just trying to get it working...
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for sirbounty's comment #a39924376
for the following reason:
Sorted it by embedding the method described at http://social.technet.microsoft.com/Forums/scriptcenter/en-US/1d9c7094-6991-4027-b7e2-d447d72dfec4/embed-a-background-image-in-a-html-code-sent-via-powershell
Essentially, the solution is laid out in this example (from the above link). I couldn't get it working with powershell's native send-mailmessage cmdlet, but it did work via the .net import of system.net.mail.mailmessag e
#Here is the template for the SMTPClient of dotNet.
$msg=new-object System.Net.Mail.MailMessag e
$msg.From='you@home.com'
$msg.to.Add('recip@somewhe re.net')
$msg.Subject='test of image'
$msg.IsBodyHtml=$true
$msg.Body='<html><body> Check this out:<br /> <img src="cid:image1"></body></ html>'
#images are found byt the 'COntentID-CID' in the body of the message
$att = new-object Net.Mail.Attachment('F:\Pr ojects\My Pictures\Output1.JPG')
$att.ContentDisposition.In line = $True
$att.ContentDisposition.Di spositionT ype = "Inline"
$att.ContentType.MediaType = "image/jpeg"
$att.ContentId = "image1"
$msg.Attachments.Add($att)
$smtp=new-object System.Net.Mail.SmtpClient
$smtp.host='smtp.myserver. com'
$smtp.Credentials=Get=Cred ential
$smtp.Send($msg)
Accepted answer: 0 points for sirbounty's comment #a39924376
for the following reason:
Sorted it by embedding the method described at http://social.technet.microsoft.com/Forums/scriptcenter/en-US/1d9c7094-6991-4027-b7e2-d447d72dfec4/embed-a-background-image-in-a-html-code-sent-via-powershell
Essentially, the solution is laid out in this example (from the above link). I couldn't get it working with powershell's native send-mailmessage cmdlet, but it did work via the .net import of system.net.mail.mailmessag
#Here is the template for the SMTPClient of dotNet.
$msg=new-object System.Net.Mail.MailMessag
$msg.From='you@home.com'
$msg.to.Add('recip@somewhe
$msg.Subject='test of image'
$msg.IsBodyHtml=$true
$msg.Body='<html><body> Check this out:<br /> <img src="cid:image1"></body></
#images are found byt the 'COntentID-CID' in the body of the message
$att = new-object Net.Mail.Attachment('F:\Pr
$att.ContentDisposition.In
$att.ContentDisposition.Di
$att.ContentType.MediaType
$att.ContentId = "image1"
$msg.Attachments.Add($att)
$smtp=new-object System.Net.Mail.SmtpClient
$smtp.host='smtp.myserver.
$smtp.Credentials=Get=Cred
$smtp.Send($msg)
So you did attach the image to the email :)
ASKER
Sorry! I totally overlooked your comment there.
Yes, that's what I've done - just had to locate the methods to accomplish this...
Thanks!
Yes, that's what I've done - just had to locate the methods to accomplish this...
Thanks!
- you have a dynamic image generated on your web server
- if you create a web page an link to that image, on the same computer, it's displayed
- you're sending that link by email
- when viewing the email, presumably from another location, you get a blank box
Why not just copy the image and attach it to the email? That way the location won't matter any more.
HTH,
Dan