Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 4
Registered: ‎12-11-2008
My Device: Not Specified
Accepted Solution

Problem sending Mails with binary attachment from BlackBerry 4.5

Hallo,

 

my well testet code, sending binary content as attached file does not work anymore on 4.5.0:

 

------------------------

// parameters given in mtehod signature
String url = "blackberry20@test";
byte[] requestdata  // ... some (really!) binary data

// create new message
final Message message = new Message();

// set receipient (as given in url)
message.addRecipients(Message.RecipientType.TO,
        new Address[]{new Address(url, url)});
       
String msgID = (DeviceInfo.getDeviceId() + "_" + System.currentTimeMillis()).toUpperCase();
message.setSubject(msgID);

// create Body .. empty text
Multipart multipart = new Multipart();
TextBodyPart txtBody = new TextBodyPart(multipart);
txtBody.setContent("");
multipart.addBodyPart(txtBody);

// create attachment and add   
SupportedAttachmentPart attachmentPart = new SupportedAttachmentPart(multipart);
attachmentPart.setContentType("application/octet-stream");
attachmentPart.setFilename(msgID);
attachmentPart.setContent(requestData);

multipart.addBodyPart(attachmentPart);
message.setContent(multipart);

// send mail in own thread
Thread thread = new Thread("Send Mail Thread") {

      public void run() {
        try {
          Transport.send(message);
        } catch (Throwable e) {
          System.err.println("error sending message " + e.getClass().getName() + "/" + e.getMessage());
        }
      }
    };
thread.start();

------------------------

 

This code was compiled with JDE 4.0 and worked fine on 4.0, 4.1, 4.2

It does _not_ work on my 4.5.0.55 testing device (BES 4.1.4) and on a customers Bold (4.6.0.X/BES >= 4.1.4)

There seems to be major changes in Attachment API on 4.5.0 that are not compatible with older versions.

- What are the workarounds?
- Are there examples how to do the work on >= 4.5?
- How be still backword compatible to 4.0, 4.1, 4.2?
- What impact does the BES/BIS-Platform have on these issues?
- Is there any reliable documentation out there how to set ContentType, Filename, etc?

 

Would be great if some had an answer (customers get angry Smiley Wink

Thanx, Jens Kinzel
 

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Problem sending Mails with binary attachment from BlackBerry 4.5

Can you describe what isn't working?  Are you getting an exception?  Does the message X out and fail to send?  Or is the attachment not being delivered?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 4
Registered: ‎12-11-2008
My Device: Not Specified

Re: Problem sending Mails with binary attachment from BlackBerry 4.5

Hallo Mark,

 

thank you for your quick answer!

 

Im sorry about leaving out the concrete problem. Here are some more details:

 

Using the mentioned code, the mail leaves the Blackberry (transfer-arrows appear, mail is marked as send).

but no mail is arriving at the target. (plain textmails do arrive)

 

I tried some other combinations of contentType and content (e.g. contentype = "text/xml", content is as a String containing an <xml>-tag pair around the Base64-encoded bytearray. In this case, the mail ist delivered to the target, but the mail had 2! attachments but both of them where empty.).

 

In case I send a plain text-mail (content-type "text/plain", content is plain  text like csv-formatted data) the

mail and the attachment is correctly delivered.

 

The code to send mail-attachments is placed in a .cod marked as library.

I put the code to send message in an extra-thread, because no mail at all was send from the blackberry when

I called the method from event-dispatch-thread.

 

Thanks for your answer, Jens

 

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Problem sending Mails with binary attachment from BlackBerry 4.5

It appears that you are adding the SupportedAttachmentPart to the MultiPart twice.  Once by passing in the MultiPart in the SupportedAttachmentPart and then again in the addBodyPart method.  You can find an example on sending attachments here.

 

How To - Create an attachment
Article Number: DB-00009

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800698/How_To_...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 4
Registered: ‎12-11-2008
My Device: Not Specified

Re: Problem sending Mails with binary attachment from BlackBerry 4.5

Hallo Mark,

thanks for comments and advice!

I tried out the sample code you gave me: I build a simple sample application calling the given code (I really did cut&paste).
I build the application with JDE 4.5.0.7 ran tests and after that with JDE 4.0.
I testet with devices with firmware versions 4.2.1.73, 4.5.0.55 and 4.6.0.126
All devices are connected to the same BES (4.1.4.15).

- All tests WORK on 4.2.1.73 (mail arrives with attachment, with correct content)
- All tests DID NOT WORK on 4.5.X and 4.6.X with the following results:
- The mail seems to be send (arrows flickering)
- The mail is NOT delivered at all
- The mail is in the mailbox marked with RED X

So here comes up more questions:
- Is there any samplecode that is PROVED to run on >=4.5?
- Are there any problems concerning BES versions?
- In your example the SupportedAttachmentPart is also added twice in the manner you mentioned
- The example covers html-attachment (ContentType "text/html"): is there an example to send real binary data?

My impression is that things get stuck with version >=4.5.

Do you have anymore ideas how to cover this problem?

Jens
BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Problem sending Mails with binary attachment from BlackBerry 4.5

I haven't been able to reproduce this.  I was also testing on a BlackBerry Bold running 4.6.0.126.  How big was the file you were trying to attach?  I tested with a 72kb file.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 4
Registered: ‎12-11-2008
My Device: Not Specified

Re: Problem sending Mails with binary attachment from BlackBerry 4.5

Hallo Mark,

I tried the example excatly as you mentioned: so the content was about 60Bytes.

Here is the code which did NOT work on >=4.5:
---------------------
public static void sendHTMLMailRIMExample(String address) throws MessagingException {

    //create a multipart
    Multipart mp = new Multipart();

//data for the content of the file
    String fileData = "<html>just a simple test</html>";
    String messageData = "Mail Attachment Demo";

//create the file
    SupportedAttachmentPart sap = new SupportedAttachmentPart(mp, "text/html", "file.html", fileData.getBytes());

    TextBodyPart tbp = new TextBodyPart(mp, messageData);

//add the file to the multipart
    mp.addBodyPart(tbp);
    mp.addBodyPart(sap);

//create a message in the sent items folder
    Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);

    Message message = new Message(folders[0]);

//add recipients to the message and send

    Address toAdd = new Address(address, address);
    Address toAdds[] = new Address[1];
    toAdds[0] = toAdd;
    message.addRecipients(Message.RecipientType.TO, toAdds);
    message.setContent(mp);

    Transport.send(message);
  }
--------------------


I found that the problem is a combination of Firmware and BES. Here are the relevant areas of the BES-Logfile:

Example 1: Mail is rejected
--------------
MAGT-Log:
[40000] (12/17 13:58:31.943):{0x14C8} [BIPP] Received datagram, Tag=64192
[40700] (12/17 13:58:31.943):{0x1534} {myBlackBerry@myCompany.de} Receiving packet from device, size=199, TransactionId=1152541538, Tag=64192, content type=CMIME, cmd=0x3
[20212] (12/17 13:58:31.943):{0x1534} {myBlackBerry@myCompany.de} StreamToMessage() failed, Tag=64192
[40275] (12/17 13:58:31.943):{0x1534} {myBlackBerry@myCompany.de} Sending transaction error to device for transaction 1152541538, size=40, TransactionId=-920681772, Tag=140390
[40279] (12/17 13:58:31.943):{0x1534} {myBlackBerry@myCompany.de} SubmitToRelaySendQ, Tag=140390
[40000] (12/17 13:58:31.943):{0x14D0} [BIPP] Send data, Tag=140390
[40279] (12/17 13:58:31.943):{0x1534} {myBlackBerry@myCompany.de} SubmitToRelaySendQ, Tag=64192
[40000] (12/17 13:58:31.943):{0x14D0} [BIPP] Send status DATA_ACCEPTED, Tag=64192
[40000] (12/17 13:58:32.896):{0x14C8} [BIPP] Received status DELIVERED, Tag=140390

DISP-Log
[30222] (12/17 13:58:31.943):{0x1104} {myBlackBerry} MFH: contentType=CMIME, sizeOTA=172, sizeOTW=162, TransactionId=1152541538, Tag=1705182
[30308] (12/17 13:58:31.943):{0x1104} [BIPPa] {myBlackBerry} Forwarding data to BES Agent (S10096620_001), size=199, intTag=64192, Tag=1705182
[30311] (12/17 13:58:31.943):{0x110C} {myBlackBerry} Forwarding status to relay, intTag=64192, Tag=1705182, Status=1
[30368] (12/17 13:58:32.896):{0x1110} {myBlackBerry} Packet has been delivered to device, Tag=233560
[30388] (12/17 13:58:32.896):{0x1110} [BIPPa] {myBlackBerry} Forwarding status to BES Agent (S10096620_001), intTag=140390, extTag=233560

ALRT-Log
[30000] (12/17 13:58:31.990):{0x5F4} EventLog::ThreadProc: Received notification, processing...
[30000] (12/17 13:58:31.990):{0x5F4} [Alarm::ActivateAlarm] Queuing alarm: <N/A> | BlackBerry Messaging Agent S-05-005 Agent 1 (Application Event Log on S-05-005) | 12/17/2008 13:58:31  (AFFF4EF4) -> {myBlackBerry@myCompany.de} StreamToMessage() failed, Tag=64192
[30000] (12/17 13:58:31.990):{0x5C0} Alarm::ThreadProc: Received an alarm message
------------------

Example 2: Mail is sent
------------------
MAGT-Log
[40000] (12/17 14:11:33.109):{0x14C8} [BIPP] Received datagram, Tag=64209
[40700] (12/17 14:11:33.109):{0x1540} {myOtherBlackBerry@myCompany.de} Receiving packet from device, size=243, TransactionId=201738721, Tag=64209, content type=CMIME, cmd=0x3
[30112] (12/17 14:11:33.125):{0x1540} {myOtherBlackBerry@myCompany.de} Receiving message from device, RefId=1323541580, Tag=64209, TransactionId=201738721
[40292] (12/17 14:11:33.687):{0x1540} {myOtherBlackBerry@myCompany.de} Email message sent for device, Tag=64209
[40279] (12/17 14:11:33.687):{0x1540} {myOtherBlackBerry@myCompany.de} SubmitToRelaySendQ, Tag=64209
[40000] (12/17 14:11:33.687):{0x14D0} [BIPP] Send status DATA_ACCEPTED, Tag=64209
-------------------------

After fiddling around with the structure of the multipart-message and MIME-Types, I found a solution that works for me:

-------------------------
private void sendRequest(String url, byte[] requestData) throws MessagingException {

    // create new message
    final Message message = new Message();

    // set receipient (as given in url)
    message.addRecipients(Message.RecipientType.TO,
        new Address[]{new Address(url, url)});

    // create subject: Device plus current timestamp
    String msgID = ("DATA"_System.currentTimeMillis()).toUpperCase();
    message.setSubject(msgID);

    // create Body .. some text
    Multipart multipart = new Multipart();
    TextBodyPart txtBody = new TextBodyPart(multipart);
    txtBody.setContent(msgID);
    multipart.addBodyPart(txtBody);

    // create attachment and add
    SupportedAttachmentPart attachmentPart = new SupportedAttachmentPart(multipart);
    attachmentPart.setContentType("text/xml");

    attachmentPart.setContent(requestData);
    attachmentPart.setFilename(msgID + ".xml");
    multipart.addBodyPart(attachmentPart);
    message.setContent(multipart);
   
    Transport.send(message);
}
------------------------

Let me say thank you for your ideas an advice. From my side the problem is closed so far -
although im not shure if it will work in all environments.

I am not shure where original problem was (Firmware / BES - Kombination ?) or something else.

Thanks,

Jens Kinzel
LINEAS Informationstechnik GmbH
D-38122 Braunschweig, Germany

 

New Developer
Posts: 88
Registered: ‎11-04-2008
My Device: Not Specified

Re: Problem sending Mails with binary attachment from BlackBerry 4.5

Hi Mark,

 

Just some clarification about this topic.

 

I read from other posts that devices >4.5.0 are not able to send attachments of more than 64KB when they are programmatically attached.

However, devices 4.5.0 and above are already able to.

Is this true? Based on my tests, i agree with this.

 

Jaclyn 

New Developer
Posts: 1
Registered: ‎09-15-2009
My Device: Not Specified

Re: Problem sending Mails with binary attachment from BlackBerry 4.5

I know this is an older thread, but I ran into this with a Altell blackberry 8330 4.5 OS so I thought it was worth noting in case anyone else ran into this. It was working previously on 4.3 but stop working after the OS upgrade. The message would show up in the mailbox as an outbound email but then have an X over it with not way to send. Something to note in my case was that I was using the Reply message on a message that came into the inbox. With the reply message triggered on a inbound message. Once I changed this to use a new message and sent it acording to the above it worked.
Highlighted
Developer
Posts: 49
Registered: ‎08-25-2009
My Device: Not Specified

Re: Problem sending Mails with binary attachment from BlackBerry 4.5

Hii,

please help me regarding this. 

 

I am trying to send the screenshot as an attachment in Email, but unable to simulate it in ESS, as well when I try to open the attachment in my sent Email folder the  error msg pops up that "This attachment type cannot be viewed on your device".

 

what is the reason behind this?? is my image which I send as .png is corrupt or something?