我到处搜寻,似乎找不到任何与我的问题有关的东西。
我需要从RN Expo应用程序以静默方式将电子邮件发送到固定的电子邮件地址,因此,当用户单击“发送”时,它将被发送而无需打开电子邮件客户端。 我已尝试使用herokuapp.com API和Node Mailer,并且已成功从Android设备而非IOS设备进行发送。在IOS上,它显示已发送电子邮件的响应,然后显示黄色警告。
我的代码正在发送通过导航道具从上一个屏幕传递的值。值之一是签名,我认为它可能是base64引起的问题,并且听说在IOS上,Print EXPO不提供base64代码,而仅提供本地URL,Node Mailer不接受且仅接受HTTPS URL和基本代码。
电子邮件需要以pdf格式发送。
如果有人对我的问题有解决方案的想法,您将是一个救星,我已经转动了好几天!
import * as Print from 'expo-print';
import * as Sharing from 'expo-sharing';
import * as MailComposer from "expo-mail-composer";
import * as FileSystem from 'expo-file-system';
export default class Materials extends Component {
pdf = async () => {
const { navigation } = this.props;
this.setState({ disabled: true });
const customer_name = navigation.getParam(
"CustomerName",
"No Customer Name"
);
const signa = navigation.getParam("sig", "No Signature");
const html = `<h1 style="text-align: center;"><strong>ALL Details</strong></h1>
<p style="text-align: center;">${customer_name}</p>
<img src="${signa}" />
`;
const html2 = `<h1 style="text-align: center;"><strong>ALL Details</strong></h1>
<h1 style="text-align: center;"><strong>ALL Details</strong></h1>
`;
console.log("signa", signa);
const pdf1url = await Print.printToFileAsync({ html });
const pdf1ur2 = await Print.printToFileAsync({ html: html2 });
let pdf1 = await FileSystem.readAsStringAsync(pdf1url.uri, {
encoding: FileSystem.EncodingType.Base64,
});
let pdf2 = await FileSystem.readAsStringAsync(pdf1ur2.uri, {
encoding: FileSystem.EncodingType.Base64,
}); // this.setState({ uri: base64 });
await fetch("EXAMPLE.COM/", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
tomail: ["test@googlemail.com"],
title: "Your code is 5015",
subject: "Enter Your subject",
base64: pdf1,
text: "some text",
pdfname: "pdfname",
}),
})
.then((response) => {
alert("email send Successfully");
response.text();
})
.then((err) => console.log(err));
// this.setState({ uri: base64 });
await fetch("EXAMPLE.COM/", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
tomail: ["test@googlemail.com""],
title: "Your code is 5015",
subject: "Enter your subject",
base64: pdf2,
text: "some text",
pdfname: "pdfname",
}),
})
.then((response) => {
console.log(response.text());
alert("end email send Successfully");
response.text();
this.setState({ disabled: true });
})
.then((err) => {
console.log(err);
// alert("Email Not send");
this.setState({ disabled: true });
});};