React Native - 使用正文打开邮件客户端

时间:2018-05-28 18:11:58

标签: javascript reactjs email 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'
  }
}

按下按钮调用此功能。所有数据都是正常的,除了正文,例如在主题中有&#34;这是主题&#34;,在邮件客户端的CC中,有&#34; cc1@example.com",但身体总是空的,我无法看到&#34;这是身体&#34;在邮件客户端。

2 个答案:

答案 0 :(得分:0)

我明白了,试试这个包。 https://github.com/anarchicknight/react-native-communications 它的使用非常简单

答案 1 :(得分:0)

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