【问题标题】:How to open an email file in a Cordova app?如何在 Cordova 应用程序中打开电子邮件文件?
【发布时间】:2018-05-14 20:51:03
【问题描述】:

我想将电子邮件文件下载到cordova.file.cacheDirectory 并在默认电子邮件应用程序中打开它们。我使用Cordova File Transfer Plugin 进行下载,使用File Opener Plugin 在默认应用程序中打开。下载部分工作正常,但是 File Opener 插件给出以下错误:

错误状态:9 - 错误消息:无法处理 UTI

我尝试打开的文件是 MIME 格式(扩展名为 .eml),我使用的 MIME 类型为 message/rfc822

function openFileWithDefaultApp(fileEntry) {
    var fileUrl = fileEntry.toURL();
    cordova.plugins.fileOpener2.open(
        fileUrl,
        'message/rfc822', {
            error: function (e) {
                console.log(
                    'Error status: ' + e.status +
                    ' - Error message: ' + e.message);
            },
            success: function () {
                console.log('file opened successfully');
            }
        }
    );
}

我错过了什么?

附:此代码与 PDF 文件完美配合。简单地切换到电子邮件文件会导致此问题。我想知道 .eml 文件是否有“默认应用程序”,还是我必须切换其他格式?一种可能性是将电子邮件转换为 PDF,但这会丢失附件。因此,这是不可取的。

【问题讨论】:

    标签: ios cordova email cordova-plugins fileopener2


    【解决方案1】:

    如果没有特定应用(例如 Klammer 或“EML 查看器”),则无法在 iOS 上打开 .eml(请参阅 https://discussions.apple.com/thread/3709613?start=0&tstart=0)。

    另一种方法是在服务器上将 .EML 转换为 .PDF,这可能有操作系统选项(例如 https://github.com/nickrussler/eml-to-pdf-converter)。

    【讨论】:

    • 谢谢,吉姆。这非常有用。我终于找到了一个可以打开 .eml 和 .msg 文件的应用程序 - Msg Viewer Pro。它使用托盘界面从 Dropbox 等打开 .eml 文件。不幸的是,它不是从 File Opener 2 触发的——我认为是因为它没有使用托盘打开应用程序。 File Opener 2 尝试根据文件扩展名或 MIME 类型获取 UTI,两者都返回“com.apple.mail.email”的 UTI。不幸的是,这不会触发 Msg Viewer Pro。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-31
    • 2018-03-20
    • 2013-06-27
    • 1970-01-01
    • 2021-05-19
    相关资源
    最近更新 更多