Results 1 to 2 of 2

Can i send the email with photo attachment from simulator? I am using JDE 4.6 ... Software & Theme Development forum

  1. #1
    sweetsweet24's Avatar
    sweetsweet24 no está en línea Stack level 1
    Join Date
    Sep 2008
    Posts
    2

    Can I send the email with photo attachment in simulator?

    Advertisement



    Can i send the email with photo attachment from simulator?
    I am using JDE 4.6 and I can send the email with text attachment but i cannot send the email with photo attachment . Can any one tell me can i send the email with photo attachment from the simulator? If can , please tell me the step by step instruction.

    thank you.

  2. #2
    sweetsweet24's Avatar
    sweetsweet24 no está en línea Stack level 1
    Join Date
    Sep 2008
    Posts
    2

    Lightbulb How can I send the photo attachment email at black berry simulator bold 900

    Here is my coding. I use the How to create an attachment from developer attachment and camera demo. I cannot send the photo attachment. What's wrong with my coding. please check my coding and tell me what is wrong. At first, I cannot send the photo with 59KB and It showed cross sign in the message box. so I reduce to 30Kb, but it send but it lost the attachment.
    Please help me!

    I use the simulator version 4.6.

    private class SaveListener implements FieldChangeListener
    {
    private byte[] _raw;
    public SaveListener(byte[] raw)
    {
    _raw = raw;
    }
    public void fieldChanged(Field field, int context)
    {
    try
    {
    FileConnection file = (FileConnection)Connector.open( FILE_NAME + _counter + EXTENSION );

    while( file.exists() )
    {
    file.close();
    ++_counter;
    file = (FileConnection)Connector.open( FILE_NAME + _counter + EXTENSION );
    }


    file.create();

    OutputStream out = file.openOutputStream();
    out.write(_raw);

    //Close the connections.
    out.close();
    file.close();



    //String filename="x-rimdevice_"+ _counter + EXTENSION;
    Bitmap image = Bitmap.createBitmapFromBytes( _raw, 0, -1, IMAGE_SCALING );
    byte[] b=getBytesFromBitmap(image);
    Multipart mp = new Multipart();
    SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,"image/bmp","x-rimdeviceimage.bmp",b);
    String a=Integer.toString(b.length);
    Dialog.inform(a);
    TextBodyPart tbp = new TextBodyPart(mp,"Send Image");
    mp.addBodyPart(tbp);
    mp.addBodyPart(sap);

    Folder folders[] = Session.getDefaultInstance().getStore().list(Folde r.SENT);

    Message message = new Message(folders[0]);
    try {
    Address toAdd = new Address("sweetsweet.khaing@gmail.com","my email");
    Address toAdds[] = new Address[1];
    toAdds[0] = toAdd;
    message.addRecipients(Message.RecipientType.TO,toA dds);
    message.setContent(mp);
    Transport.send(message);
    /////////// //Try to set timer
    } catch (Exception ex) {
    Dialog.inform(ex.toString());
    }

    // Multipart mp = new Multipart();
    //
    // //data for the content of the file
    // String fileData = "just a simple testYou are mudkjnkjeiwjikdsmvkijifjeijfidsjmckdsvmkjfkewjfinh vkjldsnmkldfmkldsfjdskljckdljvdskljfkelsfjkldsvldv nhihjfioejnfkldnvjkdbnkjvnhiewhjriewohrsdjnjkdgnkl ra;jioerewhriebnfdkjsnvkglrjiotewrhewiofjdsilgjeri jueiowhejwiofjeiworuwofjidnfvkjldhreiowrewof
    kdjkcvejwijrilfmvkldsvjerijiscfjdkvndfkljsedfwiofj egvnjlkjeidsojcvkdsnmsklvhjnieohjrierheirheiwrhjwi ohjewikfjkdlsnviorj";
    // 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(Folde r.SENT);
    //
    // Message message = new Message(folders[0]);
    //
    // //add recipients to the message and send
    // try {
    // Address toAdd = new Address("sweetsweet.khaing@gmail.com","my email");
    // Address toAdds[] = new Address[1];
    // toAdds[0] = toAdd;
    // message.addRecipients(Message.RecipientType.TO,toA dds);
    // message.setContent(mp);
    //
    // Transport.send(message);
    // } catch (Exception e) {
    // Dialog.inform(e.toString());
    // }
    //
    }
    catch(Exception e)
    {
    Dialog.alert( "ERROR " + e.getClass() + ": " + e.getMessage() );
    }

    //Inform the user where the file has been saved.
    Dialog.inform( "Saved to " + FILE_NAME + _counter + EXTENSION );

    //Increment the image counter.
    ++_counter;

    //Return to the main camera screen.
    UiApplication.getUiApplication().popScreen( _imageScreen );
    }
    }

    public byte[] getBytesFromBitmap(Bitmap bmp) {
    try {
    int height=bmp.getHeight();
    int width=bmp.getWidth();
    int[] rgbdata = new int[width*height];
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    Graphics g = new Graphics(bmp);
    bmp.getARGB(rgbdata,0,width,0,0,width,height);
    for (int i = 0; i < rgbdata.length ; i++) {
    if (rgbdata[i] != -1) {
    dos.writeInt(i);
    dos.flush();
    //l++;
    }
    }
    bos.flush();
    return bos.toByteArray();
    } catch (Exception ex) {
    Dialog.alert("getBytesFromBitmap: " + ex.toString()); return null; }
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •