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.
Thanks in Advance.
There are two ways to create/store files/images and later access them in vCO:
1. Using the file system:
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.2 Accessing Files:
220.127.116.11Access 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:
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.
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.
Thanks for your responses. Definitely looks like the right answer.
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.
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.com";
message.subject = "Message with logo";
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
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
I hope it helps.
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>
It shows up as the box with the x for bad image when i get the email.
Looks like you have forgotten one of the mime parts.
Instead of just
it should be
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.
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?