Produzione di messaggi email dinamici
È possibile creare un'email in cui il server SMTP, l'elenco di destinatari, l'oggetto, il testo e più allegati sono tutti determinati al runtime.
Informazioni su questa attività
È possibile creare un flusso di messaggi che produce un'email con più allegati. Per configurare un nodo EmailOutput per inviare una email con un singolo allegato, oggetto statico e testo statico a un elenco statico di destinatari, vedere Invio di una email con un allegato.
Le proprietà del nodo impostate durante l'invio di un'e-mail possono essere facoltative e possono essere sovrascritte in fase di esecuzione dai valori specificati nell'ambiente locale, intestazione di output dell'e-mail (EmailOutputHeader ) o il corpo del messaggio. Per utilizzare questo metodo, è necessario che i nodi precedenti nel flusso di messaggi generino tali sovrascritture. Quando non viene specificato un valore di testo nelle proprietà del nodo per il corpo principale dell'email, viene utilizzato il corpo del messaggio passato al nodo EmailOutput .
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 = 'Replaced by ESQL compute node.';
-- Add SMTP server information to the LocalEnvironment
SET OutputLocalEnvironment.Destination.Email.SMTPServer ='<smtp.server:port>';
-- Create a new message body, which will be sent as the main text of the email.
SET OutputRoot.BLOB.BLOB = CAST('This is the new text for the body of the email.' AS BLOB CCSID 1208);
RETURN TRUE;
END;SET OutputRoot.BLOB.BLOB = CAST('This is the new text for the body of the email.' AS BLOB CCSID 500);DECLARE crlf CHAR CAST(X'0D0A' AS CHAR CCSID 1208);
DECLARE myEmailBodyTxt CHAR;
SET myEmailBodyTxt [equals char] 'this is the first line' || crlf ||
'this is the second line' || crlf ||
'this is the third line';
SET OutputRoot.BLOB.BLOB = CAST(myEmailBodyTxt AS BLOB CCSID 1208);Utilizzo di un nodo JavaCompute
Informazioni su questa attività

public void evaluate(MbMessageAssembly assembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
// 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", "Replaced by Java compute node.");
// 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)
MbElement BLOB = root.createElementAsLastChild(MbBLOB.PARSER_NAME);
String text = "This is the new text for the body of the email";
BLOB.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", text.getBytes());
outMessage.finalizeMessage(MbMessage.FINALIZE_VALIDATE);
out.propagate(outAssembly); }Utilizzo dell'ambiente locale
Informazioni su questa attività
| Ambiente locale | Descrizione |
|---|---|
| Destination.Email.SMTPServer | Server:Port del server SMTP. Il valore porta è facoltativo; se non viene specificato, il valore predefinito è 25. |
| Destination.Email.SecurityIdentity | L'identità di sicurezza per l'autenticazione con il server SMTP, che può essere il nome della coppia ID utente e password definita utilizzando il comando mqsisetdbparms oppure può fare riferimento a una risorsa esterna che dispone di un attributo securityIdentity che fa riferimento a un ID utente e password definiti utilizzando il comando mqsisetdbparms . In entrambi i casi, il valore viene aggiunto dopo la stringa "smtp ::". Ad esempio, se usi il filemqsisetdbparms comando per creare un ID utente e una password di smtp::myUseridPassword, IL securityIdentity che è specificato sul nodo, o indirettamente in una risorsa esterna, lo è myUseridPassword. |
| Destination.Email.BodyContentType | Identifica che il contenuto del messaggio email contiene HTML anziché testo semplice. È possibile impostare questa proprietà su text/plain, text/html o text/xml; text/plain è il valore predefinito. |
| Destination.Email.MultiPartContentType | Il tipo di messaggio Multipart, inclusi i tipi correlato, misto e alternativo. È possibile impostare qualsiasi valore. |
| Destination.Email.Attachment.Content | L'allegato reale (testo/BLOB) o un'espressione XPath o ESQL che fa riferimento a un elemento; ad esempio, un elemento in una struttura ad albero dei messaggi o LocalEnvironment. Il valore dell'elemento cui si fa riferimento viene utilizzato come contenuto dell'allegato.
|
| Destination.Email.Attachment.ContentType | Il tipo di allegato (noto anche come Internet Media Type), che include text/plain, text/html e text/xml. È possibile impostare qualsiasi valore. |
| Destination.Email.Attachment.ContentName | Il nome dell'allegato. |
| Destination.Email.Attachment.ContentEncoding | La codifica dell'allegato: 7bit, base64 o quoted-printable.
|
Utilizzo dell'intestazione di output email
Informazioni su questa attività
| Ubicazione | Descrizione |
|---|---|
| Root.EmailOutputHeader.To | Un elenco separato da virgole di indirizzi email. |
| Root.EmailOutputHeader.Cc | Un elenco separato da virgole di indirizzi email. |
| Root.EmailOutputHeader.Bcc | Un elenco separato da virgole di indirizzi email. |
| Root.EmailOutputHeader.From | Un elenco separato da virgole di indirizzi email. |
| Root.EmailOutputHeader.Reply-To | Un elenco separato da virgole di indirizzi email. |
| Root.EmailOutputHeader.Subject | L'oggetto della email. |
| Root.EmailOutputHeader .Mittente | Un singolo indirizzo email. Questa intestazione è obbligatoria se sono specificati più indirizzi email nel file Root.EmailOutputHeader.Dal campo. |
Tutti gli altri elementi secondari dell'elemento Root.EmailOutputHeader vengono trattati come intestazioni personalizzate e vengono aggiunti anche all'e-mail in uscita.