Please provide the following:
- SDK Version: 47.0
- Platforms(mostly Android)
I need some help on how to send an Email with a created PDF via Expo and Nodemailer.
I have my Backend Function for the NodeMailer setup and tested to actually work.
In the Frontend I have tried few different Expo Packages but always had something that would not work for me.
How I want it to work is:
- On Button Press open the created PDF
- When the user wants he can close the File
- In the Background send that opened File via my NodeMailer
What I’ve tried:
await Print.printAsync({
html,
orientation: "portrait",
printerUrl: this.state.selectedPrinter?.url,
})
This creates my File and I can save it as PDF! Now this would actually work for me if I could automatically rename the File. When I press save as PDF it is called “Document” but I need to have it named dynamically. I guess if I could rename it I might be able to pick it somehow and send it (like Expo DocumentPicker or FileSystem maybe).
Second approach is to save the File and then open it:
const { uri } = await Print.printToFileAsync({ html });
console.log('File has been saved to:', uri);
try {
const cUri = await FileSystem.getContentUriAsync(uri);
await ExpoIntent.startActivityAsync("android.intent.action.VIEW", {
data: cUri,
flags: 1,
type: "application/pdf",
});
}catch(e){
console.log(e.message);
}
The Code saves my File and opens it up again. Now here is a URI I can access which looks kinda like this:
file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540xyyxwyx%252FPXXXX/Print/eb03cc8c-9c29-4d08-aed8-f10eXXX87fe5.pdf
When I try to use that URI and send it via nodemailer it tells me that the file does not exist!
Error Mail: Error: ENOENT: no such file or directory, open 'C:\Dev\Programmierung\rn\xxx-Server\file:\data\user\0\host.exp.exponent\cache\ExperienceData\%2540xxyx%252Fxxx\Print\cbcff690-d608-4138-a635-93cxxy72a2ed.pdf'
Which makes sense since that file is not available on my PC, its only inside my Emulator. How do I tell Expo the correct URI Link?
So whats important (one of the two):
- Renaming the File and save it under the correct name
- using the correct URI
I also had some approaches renaming the File using Expo Filesystem and Expo Sharing but not really the way I wanted it. If anyone could give some advice on how to achieve this would be great, or even different approaches with Expo DocumentPicker for example.