首页 > 解决方案 > 在 Ionic 框架中使用电子邮件发送附件

问题描述

我有这个代码:

this.email.isAvailable().then((available: boolean) =>{
    if(available) {
    //Now we know we can send
    }
});

let email = {
    to: 'xxx@xxx.xxx',
    attachments: [
     'file:///C:/Users/xxx/Downloads/ZZZ_RonData.txt',
     'file:///C:/Users/xxx/Downloads/ZZZZ_LogIn_Ron.txt',
     'file:///C:/Users/xxx/Downloads/ZZZZ_LogOut_Ron.txt',
     'file:///C:/Users/xxx/Downloads/ZZ_signature.png'
    ],
    subject: 'User\'s Info',
    body: '',
    isHtml: true
};

// Send a text message using default options
this.email.open(email);

上面的文件位于我的下载文件夹中,我的用户是 xxx。我确信没有拼写错误。问题是当我运行此代码时,我收到了电子邮件但没有附件。我做错了什么?

编辑:有人说我需要在位置之前放置文件,但我不确定他的意思。

编辑:类路径或我提供的代码是否存在问题。

编辑:我的路径是文件目录的正确格式吗?

这是 Ionic 给出的示例:

let email = {
  to: 'max@mustermann.de',
  cc: 'erika@mustermann.de',
  bcc: ['john@doe.com', 'jane@doe.com'],
  attachments: [
    'file://img/logo.png',
    'res://icon.png',
    'base64:icon.png//iVBORw0KGgoAAAANSUhEUg...',
    'file://README.pdf'
  ],
  subject: 'Cordova Icons',
  body: 'How are you? Nice greetings from Leipzig',
  isHtml: true
};

最终编辑:我正在使用 Visual Studio,当我按住 ctrl 单击文件路径时,文件出现了。这意味着文件目录是正确的!

标签: javascriptfileemaildebuggingionic-framework

解决方案


推荐阅读