首页 > 解决方案 > React Native - 使用正文打开邮件客户端

问题描述

我正在使用 npm pacakge 打开带有数据的邮件客户端: https ://www.npmjs.com/package/react-native-mail-compose

另外,我正在使用他们的示例:

import MailCompose from 'react-native-mail-compose';

// later in your code...
async sendMail() {
  try {
    await MailCompose.send({
      toRecipients: ['to1@example.com', 'to2@example.com'],
      ccRecipients: ['cc1@example.com'],
      bccRecipients: ['bcc1@example.com', 'bcc2@example.com'],
      subject: 'This is subject',
      text: 'This is body',
      html: '<p>This is <b>html</b> body</p>', // Or, use this if you want html body. Note that some Android mail clients / devices don't support this properly.
      attachments: [{
        filename: 'mytext', // [Optional] If not provided, UUID will be generated.
        ext: '.txt',
        mimeType: 'text/plain',
        text: 'Hello my friend', // Use this if the data is in UTF8 text.
        data: '...BASE64_ENCODED_STRING...', // Or, use this if the data is not in plain text.
      }],
    });
  } catch (e) {
    // e.code may be 'cannotSendMail' || 'cancelled' || 'saved' || 'failed'
  }
}

并在按钮按下时调用此函数。所有数据都可以,除了正文,例如在主题中有“这是主题”,在邮件客户端的抄送中,有“cc1@example.com”,但正文总是空的,我看不到“这是邮件客户端中的正文”。

标签: javascriptreactjsemailreact-native

解决方案


我已经用另一个包react-native-send-intent修复了它。它就像一个魅力!:)


推荐阅读