Invio di un messaggio MIME
È possibile inviare un'email costruita da un messaggio MIME.
Informazioni su questa attività
È possibile inoltrare un messaggio MIME al nodo EmailOutput , che utilizza il parser MIME per scrivere il messaggio MIME in un flusso di bit. Questo messaggio viene quindi inviato all'elenco di destinatari dell'intestazione EmailOutputHeader. Le sostituzioni dell'ambiente locale non vengono considerate quando viene trasmesso un messaggio MIME. non è necessario configurare il nodo EmailOutput nei seguenti esempi.
I seguenti esempi mostrano come impostare le informazioni su destinatario, mittente, oggetto, server SMTP e corpo del messaggio in ESQL (con un nodo Compute ) e Java™ (con un nodo JavaCompute ).
Utilizzo di un nodo Compute
Informazioni su questa attività

CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
-- Add recipient information to the EmailOutputHeader
SET OutputRoot.EmailOutputHeader.To = '<recipient email address>';
SET OutputRoot.EmailOutputHeader.Cc = '<recipient email address>';
SET OutputRoot.EmailOutputHeader.Bcc = '<recipient email address>';
-- Add sender information to EmailOutputHeader
SET OutputRoot.EmailOutputHeader.From = '<sender email address>';
SET OutputRoot.EmailOutputHeader."Reply-To" = '<reply email address>';
-- Add subject to EmailOutputHeader
SET OutputRoot.EmailOutputHeader.Subject = 'Dynamic MIME message in ESQL.';
-- Add SMTP server information to the LocalEnvironment
SET OutputLocalEnvironment.Destination.Email.SMTPServer ='<smtp.server:port>';
-- Create a new MIME message body, which will be sent as the main text of the email,
-- including an attachment.
CREATE FIELD OutputRoot.MIME TYPE Name;
DECLARE M REFERENCE TO OutputRoot.MIME;
-- Create the Content-Type child of MIME explicitly to ensure the correct order. If we set
-- the ContentType property instead, the field could appear as the last child of MIME.
CREATE FIELD M."Content-Type" TYPE NameValue VALUE 'multipart/related; boundary=myBoundary';
CREATE FIELD M."Content-ID" TYPE NameValue VALUE 'new MIME document';
CREATE LASTCHILD OF M TYPE Name NAME 'Parts';
CREATE LASTCHILD OF M.Parts TYPE Name NAME 'Part';
DECLARE P1 REFERENCE TO M.Parts.Part;
-- First part:
-- Create the body of the email.
-- The body of the email has the text 'This is the main body of the email.'.
CREATE FIELD P1."Content-Type" TYPE NameValue VALUE 'text/plain; charset=us-ascii';
CREATE FIELD P1."Content-Transfer-Encoding" TYPE NameValue VALUE '8bit';
CREATE LASTCHILD OF P1 TYPE Name NAME 'Data';
CREATE LASTCHILD OF P1.Data DOMAIN('BLOB') PARSE(CAST('This is the main body of the email.'
AS BLOB CCSID 1208));
CREATE LASTCHILD OF M.Parts TYPE Name NAME 'Part';
DECLARE P2 REFERENCE TO M.Parts.Part[2];
-- Second part:
-- Create the attachment of an email.
-- The attachment is called 'attachment.txt' and contains the text 'This is an attachment.'.
CREATE FIELD P2."Content-Type" TYPE NameValue VALUE 'text/plain; charset=us-ascii; name=attachment.txt';
CREATE FIELD P2."Content-Transfer-Encoding" TYPE NameValue VALUE '8bit';
CREATE LASTCHILD OF P2 TYPE Name NAME 'Data';
CREATE LASTCHILD OF P2.Data DOMAIN('BLOB') PARSE(CAST('This is an attachment.' AS BLOB CCSID 1208));
RETURN TRUE;
END;Utilizzo di un nodo JavaCompute
Informazioni su questa attività

public void evaluate(MbMessageAssembly assembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal fail = getOutputTerminal("fail");
// Create a new assembly to propagate out of this node, as we want to
// update it
MbMessage outMessage = new MbMessage();
copyMessageHeaders(assembly.getMessage(), outMessage);
MbMessage outLocalEnv = new MbMessage(assembly.getLocalEnvironment());
MbMessage outExceptionList = new MbMessage(assembly.getExceptionList());
MbMessageAssembly outAssembly = new MbMessageAssembly(assembly, outLocalEnv, outExceptionList, outMessage);
MbElement localEnv = outAssembly.getLocalEnvironment().getRootElement();
// Create the EmailOutputHeader parser. This is where we add recipient,
// sender and subject information.
MbElement root = outMessage.getRootElement();
MbElement SMTPOutput = root.createElementAsLastChild("EmailOutputHeader");
// Add recipient information to EmailOutputHeader
SMTPOutput.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "To", "<recipient email address>");
SMTPOutput.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Cc", "<recipient email address>");
SMTPOutput.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Bcc", "<recipient email address>");
// Add sender information to EmailOutputHeader
SMTPOutput.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "From", "<sender email address>");
SMTPOutput.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Reply-To", "<reply email address>");
// Add subject information to EmailOutputHeader
SMTPOutput.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Subject", "Dynamic MIME message in Java.");
// Create Destination.Email. This is where we add SMTP server information.
MbElement Destination = localEnv.createElementAsLastChild(MbElement.TYPE_NAME, "Destination", null);
MbElement destinationEmail = Destination.createElementAsLastChild(MbElement.TYPE_NAME, "Email", null);
destinationEmail.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "SMTPServer", "<smtp.server:port>");
// Set last child of root (message body) as MIME.
MbElement MIME = root.createElementAsLastChild("MIME");
// Create the Content-Type child of MIME explicitly to ensure the correct order.
MIME.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Type", "multipart/related;
boundary=myBoundary");
MIME.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-ID", "new MIME document");
MbElement parts = MIME.createElementAsLastChild(MbElement.TYPE_NAME, "Parts", null);
MbElement part, data, blob;
String text;
// First part:
// Create the body of the email.
// The body of the email has the text 'This is the main body of the email.'.
part = parts.createElementAsLastChild(MbElement.TYPE_NAME, "Part", null);
part.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Type", "text/plain; charset=us-ascii");
part.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Transfer-Encoding", "8bit");
data = part.createElementAsLastChild(MbElement.TYPE_NAME, "Data", null);
blob = data.createElementAsLastChild("BLOB");
text = "This is the main body of the email.";
try {
blob.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", text.getBytes("UTF8"));
} catch (UnsupportedEncodingException e) {
fail.propagate(outAssembly);
}
// Second part:
// Create the attachment of an email.
// The attachment is called 'attachment.txt' and contains the text 'This is an attachment.'.
part = parts.createElementAsLastChild(MbElement.TYPE_NAME, "Part", null);
part.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Type", "text/plain; charset=us-ascii;
name=attachment.txt");
part.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Transfer-Encoding", "8bit");
data = part.createElementAsLastChild(MbElement.TYPE_NAME, "Data", null);
blob = data.createElementAsLastChild("BLOB");
text = "This is an attachment.";
try {
blob.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", text.getBytes("UTF8"));
} catch (UnsupportedEncodingException e) {
fail.propagate(outAssembly);
}
outMessage.finalizeMessage(MbMessage.FINALIZE_VALIDATE);
out.propagate(outAssembly);
}