BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 03-02-2010, 05:23 AM   #1 (permalink)
New Member
 
Join Date: Mar 2010
Model: 7100T
PIN: N/A
Carrier: EES
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb cannot send image greater than 64KB

Please Login to Remove!

Hello everyone,

I am new to blackberry and i want to send an image through mail which is around 432KB large.But i am unable to do it.Can anyone help

Here is my code:

class SendEmail extends Thread
{
boolean bCanSend = false;
Store msgStore;
Folder[] folderList;
Folder outFolder;
Message msg;
Transport emailTransport;
String _emailTo,_emailBody;
Multipart mp ;
String str="Heart.png";
byte[] imgData;
private Bitmap image;
SupportedAttachmentPart sap;

String messageData = "Mail Attachment Demo";

SendEmail(String emailTo,String emailBody)
{
try
{
Session s = Session.getDefaultInstance();
image = Bitmap.getBitmapResource("Heart.png");
imgData = getBytesFromBitmap(image);
System.out.println("trying to create session");
mp = new Multipart();

if(s == null)
{
String errMsg = "Unabled to send email message.\n";
Dialog.alert(errMsg);
bCanSend = false;

}
else
{
System.out.println(" created session");
bCanSend = true;
sap = new SupportedAttachmentPart(mp, "image/bmp","Heart.bmp",imgData);
TextBodyPart tbp = new TextBodyPart(mp,messageData);

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

_emailTo = emailTo;
_emailBody = emailBody;
System.out.println("Body part added");
emailTransport = Session.waitForDefaultSession().getTransport();
msgStore = Session.waitForDefaultSession().getStore();
folderList = msgStore.list(Folder.SENT);
outFolder = folderList[0];
msg = new Message(outFolder);
System.out.println(" session method end");
}

}
catch(NoSuchServiceException nse)
{
nse.toString();
}


}

public byte[] getBytesFromBitmap(Bitmap bmp)
{
try {

System.out.println("converting bitmap");
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; }
}


public void run()
{
System.out.println("SendEmail :: running");
if(bCanSend == true)
{
try
{
Address [] addresses = new Address[1];
addresses[0] = new Address(_emailTo, _emailTo);
msg.addRecipients(Message.RecipientType.TO, addresses);
msg.setSubject("IBM Calendar Share!");
msg.setContent(mp);
emailTransport.send(msg);
System.out.println("Email has been sent");
}
catch(Exception e)
{
System.out.println("Exception caught trying to send email: " +
e.toString());
}
}
}
}



I know that SupportedAttachmentPart cannot send or receive more than 64KB but i found no other way for attachment. need this for project.This is urgent.Please help


Thanks in advance
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Cisco 8845 IP Phone - Cable - Wall Mountable - Charcoal - VoIP - Caller ID - Sp
$258.6
Cisco 8845 IP Phone - Cable - Wall Mountable - Charcoal - VoIP - Caller ID - Sp pictureAastra 9143i Backlit Display SIP VoIP Phone
$15.0
Aastra 9143i Backlit Display SIP VoIP Phone  pictureNORTEL AVAYA 1120E NTYS03 NTYS03BA IP VOIP LCD OFFICE DIGITAL POE PHONE BUSINESS
$11.0
NORTEL AVAYA 1120E NTYS03 NTYS03BA IP VOIP LCD OFFICE DIGITAL POE PHONE BUSINESS pictureAVAYA 9620 IP TELEPHONE - VOIP
$9.0
AVAYA 9620 IP TELEPHONE - VOIP pictureLot of 5 Polycom CX600 Microsoft Lync PoE VoIP Business Phone
$79.0
Lot of 5 Polycom CX600 Microsoft Lync PoE VoIP Business Phone picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.