Join Our 3 MILLION+ Members Today! Register Here | Login
Go Back   BlackBerry Forums at CrackBerry.com > BlackBerry Professionals > App Developers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
    Thread Author   #1  
Old 03-02-2010, 04:41 AM
CrackBerry Newbie
Device(s): 9520 (Storm2)
Carrier: Airtel
 
Join Date: Mar 2010
Posts: 1
Likes Received: 0
Thanked 0 Times in 0 Posts
Lightbulb Cannot send large image file as attachment through mail

Hello everyone,

I am new to BB so sorry if u find this question silly.

I want to send image as an attachment which is 432 KB in size,however SupportedAttachmentPart supports only 64 KB to send.But i need 2 send this 432KB file in mail due to the project requirement.I did not get any other method also to send file.Please help

This 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());
}
}
}
}
Reply With Quote Tip this Post
Reply
BlackBerry Forums at CrackBerry.com > > BlackBerry Professionals > App Developers   Cannot send large image file as attachment through mail

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes