?
Solved

Reproducing an html email

Posted on 2014-03-12
8
Medium Priority
?
336 Views
Last Modified: 2014-03-12
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?
0
Comment
Question by:sirbounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39924210
So let me get this straight:
- 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
0
 
LVL 67

Author Comment

by:sirbounty
ID: 39924297
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.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 39924300
Actually opening the email, viewing the source, and pasting that info in a test.html file works as well...
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 39924331
OK, so the email is OK.
What are you using to view the email? Perhaps the image is blocked at the email client level.

Do you have a web interface for your mail server where you can try to view it?

PS: I was not suggesting copying the image manually. I think you can save it using powershell and then attach it to the email.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 39924376
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...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 39924482
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.mailmessage

#Here is the template for the SMTPClient of dotNet.

$msg=new-object System.Net.Mail.MailMessage
$msg.From='you@home.com'
$msg.to.Add('recip@somewhere.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:\Projects\My Pictures\Output1.JPG')
$att.ContentDisposition.Inline = $True
$att.ContentDisposition.DispositionType = "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=Credential

$smtp.Send($msg)
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39924408
So you did attach the image to the email :)
0
 
LVL 67

Author Closing Comment

by:sirbounty
ID: 39924483
Sorry!  I totally overlooked your comment there.
Yes, that's what I've done - just had to locate the methods to accomplish this...
Thanks!
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question