MIME メッセージで構成される E メールを送信できます。
MIME メッセージを EmailOutput ノードに渡せます。このノードは MIME パーサーを使用して MIME メッセージをビット・ストリームに書き込みます。 その後、このメッセージは、EmailOutputHeader 内の受信者リストに送信されます。 ローカル環境の指定変更は MIME メッセージが渡されるときには考慮されません。 次の例では、EmailOutput ノードを構成する必要はありません。
以下の例では、ESQL (Compute ノードを使用) および Java™ (JavaCompute ノードを使用) で受信者、送信者、件名、SMTP サーバー、およびメッセージ本文の情報をセットアップする方法を示します。
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;
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);
}