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

 

 

 

  • 0
  • 0
  • 309
  • 3
  • 2

Answers

Hi Richard,

It will be because you are trying to send %Net.MailMessage as an Ensemble message. This does not extend %Persistent which is the minimum required for an Ensemble message.

You will need to create your own custom class that extends Ens.Request and have reflective properties for each of the MailMessage properties that you need at the other end. The operation will then need to create a new MailMessage from the message class.

Sean.

Yeah, just figure that...

Extends Ens.Request

Thanks, I'm just getting to grips with all of this. My first two productions (for real projects) have been completely different one was SOAP to SQL this is email attachment to hl7 and sending an email as well.
Just seems like I don't know what's coming next!!! Combined with still not going on a course I'm still feeling my way through!!!

Thanks again, under 10mins for a response!
So great that I can come here and get the answers to these little things.

Cheers

Richard
 

Interestingly, %Net.MailMessage does extend %SerialObject. So you might be able to avoid pulling the email apart and reconstructing it. You could try just creating a persistent message (extending Ens.Request an option but not necessary) with a property of type %Net.MailMessage.

 

 

My pleasure Richard.

If you've not done a course yet then your doing a great job getting this far already.

If your in the UK then I do know a very good consultant that can provide in-depth on site training and on-going developer support & mentoring...

Cheers, thanks!

Yes I'm in the UK - but with the NHS and I think my manager would prefer to send me on the course that some of the other team members have been on.

That said if you have a link to your consultant, I can forward that on to my line manager - so it can't hurt.

I've also got a contact myself (from a previous hospital) as well as team mates, just a forum like this is helpful for the small stuff espically when your getting started.

Thanks again for your time.
Richard