frencha
frencha

Reputation: 41

Problem attaching file programmatically to blackberry Email Client

I am attempting to attach an excel spreadsheet to an email programmatically, and then launch the default blackberry email client with the message as an argument. Unfortunately, I receive the error: "Email service does not support these types of attachments. Change the Send Using field or remove the attachments." The send button is not present, and there is no "Send" option in the menu; this is blocking the ability to send the email.

This error occurs when I load the package onto my physical blackberry phone, as well as in the simulator.

I am able to send the email without a hitch if I use the API instead (the commented transport.send line).

Any and all input would be greatly appreciated, and if I've overlooked some details please let me know.

public Email()
{
    try{
        message = new Message();
        multipart = new Multipart(); //Multi part can hold attachment AND body (and more)
        subject = "Service Change Request";
        multipart.addBodyPart( new TextBodyPart( multipart, "Hi XXXXXX, \n Here are the details for CLIENT" ) );
        byte[] data = null;
        InputStream stream =  MyAPP.getUiApplication().getClass().getResourceAsStream("/blank_form.xls");
        data = IOUtilities.streamToBytes(stream);
        stream.close();
        multipart.addBodyPart( new SupportedAttachmentPart( multipart, "application/octet-stream", "ServiceUpdate.xls", data ) );

        Address recipients[] = new Address[1];
        recipients[0]= new Address("*******@gmail.com", "user");

        message.setSubject(subject);
        message.setContent( multipart );
        message.addRecipients(Message.RecipientType.TO, recipients);

        //Transport.send(message);

    }catch(Exception e){

    }
}

public void send(){
    Invoke.invokeApplication( Invoke.APP_TYPE_MESSAGES, new MessageArguments( message ) );
}

Upvotes: 2

Views: 739

Answers (1)

Lugaid13
Lugaid13

Reputation: 21

EDIT: The error comes up because the simulator has no email account configured. It should work just fine on any phone that has an email account properly configured.

I hope this helps and I am not too late to lend a hand on this post.
I've worked with attachments before, and they are a pain to work with in Blckberry.

The only issue I can think of is the MIME type you are trying to use. "Application/octet-stream", try using the MIME corresponding to the extension of the attachment, for example "application/excel" for .xls files. You can find the complete list here , its the longest one I could find.

There are also some issues with the Blackberry email service and attachments that are mentioned on several Knowledge Base Articles on the official Developers page like this one, they sometimes say that the attachments have to be prefixed with "x-rimdevice" in the file name, like "x-rimdevice-serviceupdate.xls". Although I'm not really sure this affects on outgoing email, but I thought it was worth mentioning.

By the way, I'm trying to use your code for an App I'm coding right now, so I'm kind of hoping it works.

Upvotes: 2

Related Questions