How to send an email with IBM Message Broker?

5.6k views Asked by At

As a part of overall project, I need to create one Message-Broker application which accepts data in XML format and produce email.

I created one message flow like below

"MQ Input - Compute - emailoutput"

Please help me what should I write in xml file to generate the above flow.

The esql file contain the below code: 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;
2

There are 2 answers

1
TMS On

I have absolutely no idea what xml file you're talking about. Lay out msg flow in the message broker toolkit, by adding and connecting the three nodes you specified. Then add your code to the Compute Node.

0
Abu taha On

You can pass values Using XPATH, by using InputRoot.XMLNC , using Environment or LocalEnvironment. If we take your requirements , that Seems The Message come from your MQInput node you are using XMLNSC Parser.

  -- Add recipient information to the EmailOutputHeader
  SET OutputRoot.EmailOutputHeader.To = InputRoot.XMLNSC.EmailData.To;

  -- Add sender information to EmailOutputHeader
  SET OutputRoot.EmailOutputHeader.From = InputRoot.XMLNSC.EmailData.From;

  -- Add subject to EmailOutputHeader
  SET OutputRoot.EmailOutputHeader.Subject = InputRoot.XMLNSC.EmailData.Subject;

  -- Add SMTP server information to the LocalEnvironment
  -- You can Add Smtp Server From Configuration in Your Broker Administration side as Configurable Service
  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(InputRoot.EmailData.Body AS BLOB CCSID 1208);  

For Testing , In Test Client Type this XML File

<EmailData>
    <To>[email protected]</To>
    <From>[email protected]</From>
    <Subject>Testing Email App</Subject>
    <Body><![CDATA[<h1>Testing Email Data</h1><br/><hr /><br/><h6>Testing Email</h6></hr />]]></Body>
</EmailData>