将图像附加到黑莓通过代码发送电子邮件

时间:2010-09-15 14:29:18

标签: java email blackberry blackberry-simulator

将图像附加到黑莓电子邮件时出现问题。

在我的代码中,我可以附加用相机拍摄的png图像,它在附件中可见,但是当我点击发送电子邮件按钮时出现错误:

Email service does not support these types of attachments. Change the Send-Using field, or change the attachments

我的代码是:

try {
    FileConnection file = (FileConnection)Connector.open( FILE_NAME );
    if(file.exists())
    {
        InputStream stream = file.openInputStream();
        buf = IOUtilities.streamToBytes(stream);
        stream.close();
        file.close();
        SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,"image/png","collision.png",buf);
        //SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,jpegImage.getMIMEType() ,"collision.jpg",jpegImage.getData() );  
        TextBodyPart tbp = new TextBodyPart(mp,"Attachment test");
        TextBodyPart name = new TextBodyPart(mp,"Name:"+Name.getText().toString());

        mp.addBodyPart(tbp);
        mp.addBodyPart(sap);
        mp.addBodyPart(name);

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

        Message message = new Message(folders[0]);

        try {
            Address toAdd = new Address("xyz_123@yahoo.com","test email");
            Address toAdds[] = new Address[1];
            toAdds[0] = toAdd;
            message.addRecipients(Message.RecipientType.TO,toAdds);
            message.setContent(mp);
            message.setSubject("Service Request via Blackberry app");

            Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));

            //Transport.send(message);
        } 
        catch (Exception e) {
            Dialog.inform(e.toString());
        }
    }

1 个答案:

答案 0 :(得分:1)

这在模拟器上是正常的,在真实设备上试用,它会正常工作。