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

发布于 2024-09-19 04:13:34 字数 1759 浏览 5 评论 0原文

我在将图像附加到黑莓电子邮件时遇到问题。

在我的代码中,我可以附加用相机拍摄的 png 图像,并且它在附件中可见,但是当我单击“发送电子邮件”按钮时,我收到错误:

电子邮件服务不支持这些类型的附件。更改发送使用字段,或更改附件

我的代码是:

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("[email protected]","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());
        }
    }

I have a problem attaching an image to a blackberry email.

In my code I can attach a png image taken with the camera and it is visible in attachments, but when I click on the send email button I get an error:

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

My code is:

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("[email protected]","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());
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静被遗忘 2024-09-26 04:13:34

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

This is normal on the simulator, try it on a real device, it's going to work properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文