如何在React原生邮件链接中自动与邮件共享文档



我有一个共享按钮。按下这个按钮,我调用了一个函数。这个函数基本上创建了一个屏幕视图pdf,现在我将该pdf存储在我的状态中(意味着pdf路径(。之后我调用邮件链接功能。通过按下共享选项,我想将该pdf文件共享到该邮件中。这意味着,我想把pdf自动附加在邮件正文中。

以下是我尝试过的,但这只是在邮件正文中添加了一个文件路径(而不是实际的文件(:

Linking.openURL(
`mailto:support@example.com?subject=SendMail&body=${this.state.pdf}`
);

您不能使用mailto链接添加附件。很抱歉

你可以在邮件正文中放一个指向该文件的链接。

我在react原生链接中找不到任何东西。但是我发现react-native-mail对很有用

我已经在android和iOSreact-native version 0.63.2上测试过了

样本代码

/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import { View, Alert, Button } from 'react-native';
import Mailer from 'react-native-mail';
export default class App extends Component {
handleEmail = () => {
Mailer.mail({
subject: 'need help',
recipients: ['support@example.com'],
ccRecipients: ['supportCC@example.com'],
bccRecipients: ['supportBCC@example.com'],
body: '<b>A Bold Body</b>',
customChooserTitle: 'This is my new title', // Android only (defaults to "Send Mail")
isHTML: true,
attachments: [{
// Specify either `path` or `uri` to indicate where to find the file data.
// The API used to create or locate the file will usually indicate which it returns.
// An absolute path will look like: /cacheDir/photos/some image.jpg
// A URI starts with a protocol and looks like: content://appname/cacheDir/photos/some%20image.jpg
path: '', // The absolute path of the file from which to read data.
uri: '', // The uri of the file from which to read the data.
// Specify either `type` or `mimeType` to indicate the type of data.
type: '', // Mime Type: jpg, png, doc, ppt, html, pdf, csv
mimeType: '', // - use only if you want to use custom type
name: '', // Optional: Custom filename for attachment
}]
}, (error, event) => {
Alert.alert(
error,
event,
[
{text: 'Ok', onPress: () => console.log('OK: Email Error Response')},
{text: 'Cancel', onPress: () => console.log('CANCEL: Email Error Response')}
],
{ cancelable: true }
)
});
}
render() {
return (
<View style={styles.container}>
<Button
onPress={this.handleEmail}
title="Email Me"
color="#841584"
accessabilityLabel="Purple Email Me Button"
/>
</View>
);
}
}

最新更新