5

I’ve had a search around and can’t seem to find anything with the specifics of my question.

I need to send an email silently from my RN Expo app to a fixed email address, so when the user clicks SEND it gets sent WITHOUT opening up the email client. I have tried using herokuapp.com API and Node Mailer and have had success with sending from an Android device but not from an IOS device. On IOS it shows response that an email has been sent but then shows a yellow warning.

My code is sending the values which have been passed from the previous screen via navigation props. One of the values is a signature, which I think maybe causing the problem as its base64 and have heard that on IOS, Print EXPO does not provide base64 code and only provides a local URL, which Node Mailer does not accept and will only accept HTTPS URL and base code.

The email needs to be sent as a pdf.

If anyone has any idea of a solution to my problem you would be a lifesaver, I have been spinning my wheels for days!

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 });
  });};

enter image description here

LyonsTheWay2Gold
  • 363
  • 1
  • 11

0 Answers0