VMware Cloud Community
airinaga
Contributor
Contributor
Jump to solution

Automated email script (dynamic wrapper)

Hey everyone,

   I am running the 'Relocate Virtual Machine Disk' workflow, and would like for it to generate a simple email stating which VM and what Datastore the new disks are living in. The text enlarged and in bold is what I had added to the original 'Send Notification' script. I would like a clean looking email without the "Dynamic Wraper" and Instance stuff.

Here is my 'Send Email' script:

var message = new EmailMessage();

// Override default settings if and only if input parameter is set

if ( smtpHost != null && smtpHost.length > 0 ){

    message.smtpHost = smtpHost;

}

if ( smtpPort != null && smtpPort > 0 ){

    message.smtpPort = smtpPort;

}

if ( username !=null && username.length > 0){

    message.username = username;

}

if ( password != null && password.length > 0){

    message.password = password;

}

if ( fromName != null && fromName.length > 0){

    message.fromName = fromName;

}

if ( fromAddress != null && fromAddress.length > 0){

    message.fromAddress = fromAddress;

}

message.toAddress = toAddress;

message.subject = subject;

message.addMimePart( "Virtual Machine: " + vm + "Relocated disk to: " + datastore, "text/html; charset=UTF-8");

System.log( "sending mail to host: " + message.smtpHost + ":" + message.smtpPort + " with user:" + message.username

            + ", from:" + message.fromAddress + ", to:" + message.toAddress );

message.sendMessage();

And this is the email that I am receiving:

Virtual Machine: DynamicWrapper (Instance) : [VcVirtualMachine]-[class com.vmware.vmo.plugin.vi4.model.VimVirtualMachine] -- VALUE : VirtualMachine'Test VM'Relocated disk to: DynamicWrapper (Instance) : [VcDatastore]-[class com.vmware.vmo.plugin.vi4.model.VimDatastore] -- VALUE : Datastore'Windows_Lab'

Reply
0 Kudos
1 Solution

Accepted Solutions
qc4vmware
Virtuoso
Virtuoso
Jump to solution

Use vm.name and datastore.name.  Also for simple text formatting you can use methods on the string.  So if you want the vm.name in bold and at a 16 point font you could say:

vm.name.bold().fontsize.("16");

You can google the full list of options for javascript.  You can also just include the markup in the string like you did above.

View solution in original post

Reply
0 Kudos
1 Reply
qc4vmware
Virtuoso
Virtuoso
Jump to solution

Use vm.name and datastore.name.  Also for simple text formatting you can use methods on the string.  So if you want the vm.name in bold and at a 16 point font you could say:

vm.name.bold().fontsize.("16");

You can google the full list of options for javascript.  You can also just include the markup in the string like you did above.

Reply
0 Kudos