All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cloudslang.content.mail.actions.SendMailAction Maven / Gradle / Ivy

There is a newer version: 0.0.53
Show newest version
package io.cloudslang.content.mail.actions;

import com.hp.oo.sdk.content.annotations.Action;
import com.hp.oo.sdk.content.annotations.Output;
import com.hp.oo.sdk.content.annotations.Param;
import com.hp.oo.sdk.content.annotations.Response;
import com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType;
import com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType;
import io.cloudslang.content.mail.entities.SendMailInputs;
import io.cloudslang.content.mail.services.SendMail;
import org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by giloan on 10/30/2014.
 */
public class SendMailAction {

    /**
     * The operation sends a smtp email.
     *
     * @param hostname The hostname or ip address of the smtp server.
     * @param port The port of the smtp service.
     * @param htmlEmail The value should be true if the email is in rich text/html format.
     *                  The value should be false if the email is in plain text format.
     *                  Valid values: true, false. Default value: true.
     * @param from From email address.
     * @param to A delimiter separated list of email address(es) or recipients where the email will be sent.
     * @param cc A delimiter separated list of email address(es) or recipients, to be placed in the CC.
     * @param bcc A delimiter separated list of email address(es) or recipients, to be placed in the BCC.
     * @param subject The email subject. If a subject spans on multiple lines, it is formatted to a single one.
     * @param body The body of the email.
     * @param readReceipt The value should be true if read receipt is required, else false. Valid values: true, false. Default value: false.
     * @param attachments A delimited separated list of files to attach (must be full path).
     * @param user If SMTP authentication is needed, the username to use.
     * @param password If SMTP authentication is needed, the password to use.
     * @param delimiter A delimiter to separate the email recipients and the attachments. Default value: ','.
     * @param characterSet The character set encoding for the entire email which includes subject, body,
     *                     attached file name and the attached file.
     *                     
Valid values: UTF-8, UTF-16, UTF-32, EUC-JP, ISO-2022-JP, Shift_JIS, Windows-31J. Default value: UTF-8. * @param contentTransferEncoding The content transfer encoding scheme (such as 7bit, 8bit, base64, quoted-printable etc) * for the entire email which includes subject, body, attached file name and the attached file. . * Valid values: quoted-printable, base64, 7bit, 8bit, binary, x-token. Default value: quoted-printable (or Q Encoding). * @param encryptionKeystore The path to the pks12 format keystore to use to encrypt the mail. * @param encryptionKeyAlias The alias of the key from the encryptionKeystore to use to encrypt the mail. * @param encryptionKeystorePassword The password for the encryptionKeystore. * @param timeout The timeout (seconds) for sending the mail messages. * @return a map containing the output of the operation. The keys present in the map are *
returnResult - that will contain the SentMailSuccessfully if the mail was sent successfully. *
returnCode - the return code of the operation. 0 if the operation goes to success, -1 if the operation goes to failure. *
exception - the exception message if the operation goes to failure. * @throws Exception */ @Action(name = "Send Mail", outputs = { @Output(SendMail.RETURN_RESULT), @Output(SendMail.RETURN_CODE), @Output(SendMail.EXCEPTION) }, responses = { @Response(text = SendMail.SUCCESS, field = SendMail.RETURN_CODE, value = SendMail.SUCCESS_RETURN_CODE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = SendMail.FAILURE, field = SendMail.RETURN_CODE, value = SendMail.FAILURE_RETURN_CODE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR) } ) public Map execute( @Param(value = SendMailInputs.HOSTNAME, required = true) String hostname, @Param(value = SendMailInputs.PORT, required = true) String port, @Param(value = SendMailInputs.HTML_EMAIL) String htmlEmail, @Param(value = SendMailInputs.FROM, required = true) String from, @Param(value = SendMailInputs.TO, required = true) String to, @Param(SendMailInputs.CC) String cc, @Param(SendMailInputs.BCC) String bcc, @Param(value = SendMailInputs.SUBJECT, required = true) String subject, @Param(value = SendMailInputs.BODY, required = true) String body, @Param(SendMailInputs.READ_RECEIPT) String readReceipt, @Param(SendMailInputs.ATTACHMENTS) String attachments, @Param(SendMailInputs.HEADERS) String headers, @Param(SendMailInputs.HEADERS_ROW_DELIMITER) String rowDelimiter, @Param(SendMailInputs.HEADERS_COLUMN_DELIMITER) String columnDelimiter, @Param(SendMailInputs.USER) String user, @Param(SendMailInputs.PASSWORD) String password, @Param(SendMailInputs.DELIMITER) String delimiter, @Param(SendMailInputs.CHARACTERSET) String characterSet, @Param(SendMailInputs.CONTENT_TRANSFER_ENCODING) String contentTransferEncoding, @Param(SendMailInputs.ENCRYPTION_KEYSTORE) String encryptionKeystore, @Param(SendMailInputs.ENCRYPTION_KEY_ALIAS) String encryptionKeyAlias, @Param(SendMailInputs.ENCRYPTION_KEYSTORE_PASSWORD) String encryptionKeystorePassword, @Param(SendMailInputs.ENABLE_TLS) String enableTLS, @Param(SendMailInputs.TIMEOUT) String timeout, @Param(SendMailInputs.ENCRYPTION_ALGORITHM) String encryptionAlgorithm ) throws Exception { SendMailInputs sendMailInputs = new SendMailInputs(); sendMailInputs.setSmtpHostname(hostname); sendMailInputs.setPort(port); sendMailInputs.setHtmlEmail(htmlEmail); sendMailInputs.setFrom(from); sendMailInputs.setTo(to); sendMailInputs.setCc(cc); sendMailInputs.setBcc(bcc); sendMailInputs.setSubject(subject); sendMailInputs.setBody(body); sendMailInputs.setReadReceipt(readReceipt); sendMailInputs.setAttachments(attachments); sendMailInputs.setHeaders(headers); sendMailInputs.setRowDelimiter(rowDelimiter); sendMailInputs.setColumnDelimiter(columnDelimiter); sendMailInputs.setUser(user); sendMailInputs.setPassword(password); sendMailInputs.setDelimiter(delimiter); sendMailInputs.setCharacterset(characterSet); sendMailInputs.setContentTransferEncoding(contentTransferEncoding); sendMailInputs.setEncryptionKeystore(encryptionKeystore); sendMailInputs.setEncryptionKeyAlias(encryptionKeyAlias); sendMailInputs.setEncryptionKeystorePassword(encryptionKeystorePassword); sendMailInputs.setEnableTLS(enableTLS); sendMailInputs.setTimeout(timeout); sendMailInputs.setEncryptionAlgorithm(encryptionAlgorithm); try { return new SendMail().execute(sendMailInputs); } catch (Exception e) { return exceptionResult(e.getMessage(), e); } } private Map exceptionResult(String message, Exception e) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); String eStr = writer.toString().replace("" + (char) 0x00, ""); Map returnResult = new HashMap<>(); returnResult.put(SendMail.RETURN_RESULT, message); returnResult.put(SendMail.RETURN_CODE, SendMail.FAILURE_RETURN_CODE); returnResult.put(SendMail.EXCEPTION, eStr); return returnResult; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy