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

New Developer
Posts: 1
Registered: ‎01-07-2009
My Device: Not Specified

Sending an image as an attachment

Hey everyone,

I'm new to blackberry development. I've gone through numerous posts on the same subject and I'm still a little confused. From what I understand, the ESS on the blackberry simulator has some limitations which prevents us from sending large attachment files (over 4 kb). Has anyone figured out yet how to get around this problem?


Also, I've been facing another problem. I tried attaching a small PNG image about 2kb in size. When I tried sending the image as an attachment, in the ESS I got an error saying content type 5 not implemented. However, the mail was sent successfully without the attachment. I've attached my code below, please let me know what's wrong.



public class EmailSample extends MainScreen {
            private AutoTextEditField subjectField, msgField;
            private EditField toField;
            private byte[] rawone;
            private Bitmap _createphoto=Bitmap.getBitmapResource("auto.png");

            public EmailSample(byte[] raw) {
                LabelField title = new LabelField("Send Image",
                                LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
                toField = new EditField("To: ", "", Integer.MAX_VALUE, BasicEditField.FILTER_EMAIL);
                subjectField = new AutoTextEditField("Subject: ", "New Mail", 30, BasicEditField.FILTER_DEFAULT);
                //ignore this
                rawone = raw;
                //_createphoto = Bitmap.createBitmapFromBytes(rawone, 0, -1, 7);
                //BitmapField photo = new BitmapField(_createphoto);
                add(new SeparatorField());

            //create a Send menu item to send the email message
            private MenuItem _sendItem = new MenuItem("Send", 110, 10) {
                public void run() {
                    DataBuffer db = new DataBuffer();
                    int width=_createphoto.getWidth();
                    int height=_createphoto.getHeight();
                    int[] rgbdata = new int[width*height];
                    byte[] ba;
                    _createphoto.getARGB(rgbdata, 0, width, 0, 0, width, height);
                     for (int i = 0; i < (width * height); i++)


                    ba = db.getArray();
                    Multipart mp = new Multipart();
                    //data for the content of the file
                    String messageData = "Sending Photo";
                    SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,"image/bmp" ,"image.bmp",ba );    
                    TextBodyPart tbp = new TextBodyPart(mp,messageData);

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

                    Message msg = new Message(folders[0]);
                    Address toList[] = new Address[1];
                    try {
                         toList[0]= new Address(toField.getText(), "");
                    } catch(AddressException e) {
                    try {
                        msg.addRecipients(Message.RecipientType.TO, toList);
                    } catch(MessagingException e) {
                         //handle exception

                     //send the message using the static Transport.send method
                     //then reset UI fields to be empty
                     try {
                     } catch(MessagingException e) {

           //override makeMenu to add the Send and Close menu items to the menu
           protected void makeMenu( Menu menu, int instance )

Thanking you in advance.

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

Re: Sending an image as an attachment

You can work around the ESS limitations by testing on a real BlackBerry handheld or by connecting the BlackBerry Simulator to a BlackBerry Enterprise Server.  The link below has steps on how to do so.


How To - Connect the BlackBerry Device Simulator to a BlackBerry Enterprise Server
Article Number: DB-00049


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