virtualportal
Enthusiast
Enthusiast

vCO Mail Plugin - images in emails

Hi,

I am looking to send a HTML formatted email with Images using the vCO Mail plugin.

I am using the vCO appliance and was wondering where I can store the images to make them available from my html email content? I did try to create a directory (/tmp/images/image.jpg) on the Suse Server and upload the image there but when I sent the email the image could not be found.

The only option right now is to host these images elsewhere on the web and link to them that way, but if I could embed them into the email message and store them locally that would be much better.

Any ideas?

Thanks in Advance.

Steve

0 Kudos
9 Replies
virtualportal
Enthusiast
Enthusiast

Also to add to this, I would like to also attach a file to an email.. Where can this file be hosted so that it is accessible? Would it be the same place?

Thanks

0 Kudos
igorstoyanov
VMware Employee
VMware Employee

There are two ways to create/store files/images and later access them in vCO:

1. Using the file system:

    1.1 Configuration:

         1.1.1 Setting Server File System Access: http://pubs.vmware.com/vsphere-50/topic/com.vmware.vsphere.vco_dev.doc_42/GUID-A94A6C16-1439-46AF-BD...

          1.1.2 Set JavaScript Access to Operating System Commands:  http://pubs.vmware.com/vsphere-50/topic/com.vmware.vsphere.vco_administer.doc_42/GUID-F4995BD2-F2F7-...

   1.2 Accessing Files:

       1.2.1 Accessing the Orchestrator Server File System from JavaScript and Workflows : http://pubs.vmware.com/vsphere-50/topic/com.vmware.vsphere.vco_dev.doc_42/GUID-A5FA1E2D-56AE-4103-A4...

                1.2.1.1Access the Server File System Using the System.getTempDirectory Method: http://pubs.vmware.com/vsphere-50/topic/com.vmware.vsphere.vco_dev.doc_42/GUID-A5FA1E2D-56AE-4103-A4...

       1.2.2 File System Scripting Examples: http://pubs.vmware.com/vsphere-50/topic/com.vmware.vsphere.vco_dev.doc_42/GUID861E9D4E-BA4D-4CE3-B42...

2. Use vCO resource elements - you can store the files/images within vCO:

  2.1 Resource Elements: http://pubs.vmware.com/vsphere-50/topic/com.vmware.vsphere.vco_dev.doc_42/GUID-A94A6C16-1439-46AF-BD...

I would recommend using vCO resource elements for this purpose since they would be part of the workflow package and could be exported/imported together with your workflows/actions.

Visit http://blogs.vmware.com/orchestrator for the latest in Cloud Orchestration.
0 Kudos
sanchezs
VMware Employee
VMware Employee

Hi,

The Mail plug-in allows to embed MIME content inside the messages that you want to send by using the addMimePart() method, depends on the content type that you specify. See

As igorstoyanov pointed out, you could use a local file or a resource element and to attach it (its content) to your e-mail message. In this blog post you can see an example about how to generate and save a zip file on a vCO server (with some vCO logs) and to send it after that attached by e-mail:

I hope it helps.

Sergio

0 Kudos
virtualportal
Enthusiast
Enthusiast

Thanks for your responses. Definitely looks like the right answer. Smiley Happy

I am trying to find the path to the image that I have added as a resource element now though.

I have added the jpg as a resource element and created attribute named logo. I then created a string that looks similar to:

var emailHtml = "<html<body><img src=\"" + logo + "\" alt=\"Logo\"/></body></html>"

This string was then used as the string of HTML that would make up the content of the email body.

When i tried executing this workflow the image didnt show in the mail. Is there a method such as logo.path? The auto complete doesnt seem to be working on my vCO Client script editor, so I am not having much luck finding the correct methods etc. (anyone know why the autocomplete wouldnt be working?)

I guess the other option would be to use the file system access, but again I would need the path and I would much prefer to include these small images as resources when I export my workflow.

Thanks

0 Kudos
sanchezs
VMware Employee
VMware Employee

Hi,

Did you solve that issue? If yes, great! if no, you can try with these steps:

1) Create a new Resource Element containing your image file. See attached file.

2) Add that Resource Element to a new Configuration Element. See attached file.

3) Add an Attribute to your workflow of type ResourceElement and link its value with the Resource with the image from the Configuration Element. See attached file.

4) Pass the Attribute to the scripting element of your workflow and do the following:

var logo = logoResource.getContentAsMimeAttachment();

var emailHtml = "<html><body>This is the logo <img src=\"cid:" + logo.name +  "\" alt=\"Logo\"/></body></html>";

var message = new EmailMessage();
message.toAddress = "email@example.org";
message.subject = "Message with logo";
message.addMimePart(emailHtml, "text/html");
message.addMimePart(logo, null);

message.sendMessage();

The important parts are to get the resource as MIME attachment and to set the proper src for the img element inside the HTML message. If you follow those steps it should work Smiley Happy

And if you want to use a directly a file from the file system (without Resource Elements, Configuration Elements and Attributes) you can load the logo variable as:

var logo = new MimeAttachment(System.appendToPath(System.getTempDirectory(), "vcoexample.png"));

Where "vcoexample.png" is the filename of the image that you want to use, and the value of "System.getTempDirectory()" is the full path to the directory that contains the file (in that case is the temporary directory, but you can use any directory that you know that vCO has access to). It should work in this way as well Smiley Happy

I hope it helps.

Sergio

0 Kudos
JMC13
Contributor
Contributor

I know this is an old thread but I need to do something similar and this doesnt seem to work.

I set the logo using logo = logoRes.getContententAsMimeAttachment() from a resource element (png file)

Then i use

var emailHtml = "<html><body>This is the logo <img src=\"cid:" + logo.name +  "\" alt=\"Logo\"/></body></html>

and

message.addMimePart(emailHtml, "text/html");

It shows up as the box with the x for bad image when i get the email.  

0 Kudos
iiliev
VMware Employee
VMware Employee

Looks like you have forgotten one of the mime parts.

Instead of just

message.addMimePart(emailHtml, "text/html");


it should be

message.addMimePart(emailHtml, "text/html");

message.addMimePart(logo, null);



0 Kudos
JMC13
Contributor
Contributor

I had that originally,  but all that does is attach the image as an actual attachment.  That does work and you can click on the image and see it, however even with this part the other part where the image is supposed to just show in the email does not work.

0 Kudos
iiliev
VMware Employee
VMware Employee

Hmm, I tried it in my environment and it seems to work - image is shown inside the email.

What email client do you use? Perhaps it is some configurable setting in the email client to show images as attachments or not?

0 Kudos