Task Name | Send e-mail with attachment file from UCSD |
Description | |
Prerequisites | - Tested on 5.4
|
Category | Workflow |
Components | vSphere 5.x |
User Inputs | e-mail address |
Output | e-mail with counter |
Instructions for Regular Workflow Use:
- Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
- Unzip the file on your computer. Should end up with a .WFD file.
- Log in to UCS Director as a user that has "system-admin" privileges.
- Navigate to "Policies-->Orchestration" and click on "Import".
- Click "Browse" and navigate to the location on your computer where the .WFDX file resides. Choose the .WFDX file and click "Open".
- Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
- Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
- Click "Submit".
- A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment
A thank you goes out to Tejeswar Sahu
The task inputs:
The resulting e-mail:
The Code in the custom task:
importPackage(com.cloupia.lib.util.mail);
importPackage(com.cloupia.feature.cloudsense);//CloudSenseUtil
importPackage(java.lang);
importPackage(java.io);
importPackage(java.net);
importPackage(javax.mail);
importPackage(javax.mail.internet);//MimeBodyPart
importPackage(javax.activation);//FileDataSource
//////// FOR SENDING MAIL WITH ATTACHING THE FILE /////////////////////
var fullPathOfFile = input.location;
var toAddress = input.address;
var subject = input.subject;
var body = input.body;
var mailSettings = CloudSenseUtil.getMailSettings();
var fromAddr = mailSettings.getFromEmailAddress();
logger.addInfo("from address : " + fromAddr+":::"+"to address : " + toAddress+":::"+"Subject:"+subject);
logger.addInfo(mailSettings.getFromEmailAddress()+":"+mailSettings.getSmtpServer()+":"+mailSettings.getSmtpUser()+":"+
mailSettings.getSmtpPass()+":"+mailSettings.getSmtpPort());
var sourceFile = new File(fullPathOfFile);
var messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(body);
var multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
var pdfFile = new File(sourceFile);
var fds = new FileDataSource(pdfFile);
messageBodyPart.setDataHandler(new DataHandler(fds));
var fileName = pdfFile.getName();
logger.addInfo("File name is :"+fileName+":");
messageBodyPart.setFileName(fileName);
multipart.addBodyPart(messageBodyPart);
MailManager.sendEmailBuiltIn(mailSettings, multipart, fromAddr, subject, toAddress);
logger.addInfo("Message sent successfully.");