Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Sending an email that you have just received

Question
Richard Housham · Apr 27, 2017

Sending an email that you have just received

Hi I'm hoping the community will once more help me out with a question!

Right I have a production that takes an attachment from an email and processes it, sending out a hl7 message at the end. This works ok.

Now I just need to take the email and send it back out to a 'backup' email address, basically giving
a) A backup incase there is a problem with the email or something else further down the line.
b) A log of the emails receieved.

So I thought the best thing to do is have an operation with an email adapter and to send that my message.

That gave me some code that's basically like this.

Class eReferral.EmailAdapter Extends Ens.BusinessService
{

Parameter ADAPTER = "eReferral.eRefInboundAdapter";

Method OnProcessInput(pInput As %Net.MailMessage, pOutput As %RegisteredObject) As %Status 

{

 set newMessage = pInput.%ConstructClone()
   
   do ..SendRequestSync("sendBackup",newMessage,.pResp)
   $$$TRACE($ZCVT($ZERROR,"O","HTML"))

//more things to process the attatchment

Quit $$$OK

}

}

Then I have the sendBackup service as
 

/// Send the email from the service to a backup email address
Class eReferral.SendBackupEmail Extends Ens.BusinessOperation
{

Parameter ADAPTER = "EnsLib.EMail.OutboundAdapter";

Property Adapter As EnsLib.EMail.OutboundAdapter;

Parameter INVOCATION = "Queue";

Method SendEmail(pInput As %Net.MailMessage, Output pOutput As Ens.Response) As %Status
{

do pInput.To.Clear()

do pInput.To.Insert(..Adapter.Recipient)

set pInput.From  = ..Adapter.SMTP.authenticator.UserName

Set tSc=..Adapter.SendMail(email)

Quit tSc
}

XData MessageMap
{
<MapItems>
  <MapItem MessageType="%Net.MailMessage">
    <Method>SendEmail</Method>
  </MapItem>
</MapItems>
}

}
 

But I get
ERROR #5002: Cache error: <SUBSCRIPT>%SaveData+23^Ens.MessageHeader.1 ^Ens.MessageHeaderI("MessageBodyId","UTF-8

On the EmailAdapter object when I make that call do the "sendBackup" object.
What am I doing wrong - how can I debug this? 
 

Thanks 
Regards

Richard

#Caché #Debugging #Business Operation #Business Service #Ensemble

Source URL:https://community.intersystems.com/post/sending-email-you-have-just-received