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

Computer Analog Instrument Number Readout German 24 Volt FS066 National Lab Lot
$100.0
Computer Analog Instrument Number Readout German 24 Volt FS066 National Lab Lot  pictureMEASUREMENT COMPUTING 193791A-01 PCI-DAS1000 ANALOG MULTIFUNCTION 16 CH BOARD
$199.0
MEASUREMENT COMPUTING 193791A-01 PCI-DAS1000 ANALOG MULTIFUNCTION 16 CH BOARD pictureMeasurement Computing PCI-DAS1602/16 High-Speed Analog Input Board
$295.0
Measurement Computing PCI-DAS1602/16 High-Speed Analog Input Board pictureJeppesen Student CSG JS514101 Flight Computer & Slide Graphic Computer Manual
$10.75
Jeppesen Student CSG JS514101 Flight Computer & Slide Graphic Computer Manual pictureIOTech ADC488/16 Measurement Computing Analog-Digital Converter ADC
$36.04
IOTech ADC488/16 Measurement Computing Analog-Digital Converter ADC picture






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