ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Java msgflow: EmailOutput node to send binary attachments

Post new topic  Reply to topic
 Java msgflow: EmailOutput node to send binary attachments « View previous topic :: View next topic » 
Author Message
upsidedown
PostPosted: Wed Nov 27, 2013 2:20 am    Post subject: Java msgflow: EmailOutput node to send binary attachments Reply with quote

Newbie

Joined: 27 Nov 2013
Posts: 2

Hi everyone,

I'm using Message Broker Toolkit Version: 7.0.0, and I'm trying to send an email will a .gzip attachment.

I can attach text files fine, but I don't think I am doing the encoding right for binary files.

Code:

.
.
.

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", "mailhost.mfil.local:25");

//attachmentElement.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "ContentEncoding", "base64");

attachmentElement.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "ContentName", "error.gz");
attachmentElement.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content", compress("hello".getBytes()));
.
.
.
//propagate to EmailOutput




Code:

   public static String compress(byte[] uncompressed) throws IOException {
      ByteArrayOutputStream os = new ByteArrayOutputStream(uncompressed.length);
      GZIPOutputStream gos = new GZIPOutputStream(os);
      gos.write(uncompressed);
      gos.close();
      byte[] compressed = os.toByteArray();
      String s = new String(compressed);
      //return DatatypeConverter.printBase64Binary(compressed);
      return s;
   }



I've tried encoding as base64, but I still couldn't get it to work.

Thanks in advance for any help.
Back to top
View user's profile Send private message
smdavies99
PostPosted: Wed Nov 27, 2013 2:30 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

I've done this a long time ago. I don't have access to the code but here is how I got it sorted.

I took the sample flow and added a load of trace nodes to show things like

${LocalEnvironment}
${Root}
${Environment}

and then I used the facility in the sample to add attachments. Then run it with usertrace to find out it was constructing the message it sends to the EmailOutput Node.

Then I replicated that in my flow.

At the time, I was using the IA99 Support pack (ZIP Node) to zip up my package. That is no longer available/works on later versions but what you are doing seems right in principle.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
Esa
PostPosted: Wed Nov 27, 2013 2:53 am    Post subject: Re: Java msgflow: EmailOutput node to send binary attachment Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

upsidedown wrote:

I've tried encoding as base64, but I still couldn't get it to work.


Define work.

The message you are constructing, is it using MIME parser?
Back to top
View user's profile Send private message
upsidedown
PostPosted: Wed Nov 27, 2013 3:07 am    Post subject: Re: Java msgflow: EmailOutput node to send binary attachment Reply with quote

Newbie

Joined: 27 Nov 2013
Posts: 2

Esa wrote:
[
Define work.


The file gets attached but it is not a valid file when I try opening it.

Esa wrote:
[
The message you are constructing, is it using MIME parser?


I set the 'ContentEncoding', if that is what you mean.
Back to top
View user's profile Send private message
Esa
PostPosted: Wed Nov 27, 2013 4:35 am    Post subject: Re: Java msgflow: EmailOutput node to send binary attachment Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

upsidedown wrote:


I set the 'ContentEncoding', if that is what you mean.


No, it's not. Click 'MIME' in my previous post and you see what I mean.

You must buid a MIME tree and put the attachments under OutputRoot.MIME.Parts as in the MIME tree diagram. If you propagate the MIME tree to an EmailOutput -- or any other output node -- the MIME parser will serialize the tree and construct the message for you, even base64encode the attachments.

Never done it myself yet, but that's the way it's supposed to work.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Java msgflow: EmailOutput node to send binary attachments
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.