-
Examine the email message and decide how to use it.
Email messages can have a variety of different structures, which would need different handling. You may want to start by making sure that the message has the structure you expect. That is, you would check whether it is a multipart message and whether the parts are binary. For more information, see Using Email Messages.
-
Once you are sure of the message structure, use the other properties of %Net.MailMessageOpens in a new tab to access the message body or any headers. See Using Email Messages.
-
Create an instance of the request message, which will be the message that your business service sends.
For information on creating message classes, see Defining Messages.
-
For the request message, set its properties as appropriate, using values in the email message.
-
Call a suitable method of the business service to send the request to some destination within the production. Specifically, call SendRequestSync(), SendRequestAsync(), or (less common) SendDeferredResponse(). For details, see Sending Request Messages.
Each of these methods returns a status (specifically, an instance of %StatusOpens in a new tab).
-
Make sure that you set the output argument (pOutput). Typically you set this equal to the response message that you have received. This step is required.
-
Return an appropriate status. This step is required.
Method OnProcessInput(pInput As %Net.MailMessage,
pOutput As %RegisteredObject) As %Status
{
//Check if mail message has multiple parts
Set multi=pInput.IsMultiPart
If multi
{$$$TRACE("This message has multiple parts; not expected")
Quit $$$ERROR($$$GeneralError,"Message has multiple parts")
}
//Check if mail message is binary
Set bin=pInput.IsBinary
If bin
{$$$TRACE("This message is binary; not expected")
Quit $$$ERROR($$$GeneralError,"Message is binary")
}
//Check if mail message is HTML
Set html=pInput.IsHTML
If html
{$$$TRACE("This message is HTML not expected")
Quit $$$ERROR($$$GeneralError,"Message is HTML")
}
//now safe to get text of message
Set pReq=##class(EEMA.EmailContents).%New()
Set pReq.MessageText=pInput.TextData
Set tSc=..SendRequestSync("EEMA.EmailProcessor",pReq,.pResp)
Set pOutput=pResp
Quit tSc
}