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

1pc Yaskawa MP920 CPU-01
$719.58
1pc Yaskawa MP920 CPU-01 picture1pc Siemens S5 CPU 6ES5 945-7UA13 115U 945 CPU
$1352.78
1pc Siemens S5 CPU 6ES5 945-7UA13 115U 945 CPU pictureLot of 2 MITUTOYO DP-3 Digimatic Mini Processor used no power supplies (A-74)
$14.99
Lot of 2 MITUTOYO DP-3 Digimatic Mini Processor used no power supplies (A-74) picture150x69x36MM Aluminium Heat Diffuse Heat Sink Cooling Fin Radiator Fr CPU IC LED
$11.99
150x69x36MM Aluminium Heat Diffuse Heat Sink Cooling Fin Radiator Fr CPU IC LED picture150x69x36MM Aluminium Heat Diffuse Heat Sink Cooling Fin Radiator Fr CPU IC LED
$12.48
150x69x36MM Aluminium Heat Diffuse Heat Sink Cooling Fin Radiator Fr CPU IC LED picture






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