react-native-mail
react-native-mail copied to clipboard
Email with attachement fails
I am trying to send a photo by mail with the help of this module and get the following error:
index.ios.bundle:28842Exception '-[MFMailComposeInternalViewController addAttachmentData:mimeType:fileName:] attachment must not be nil.' was thrown while invoking mail on target RNMail with params (
{
attachment = {
name = Ladunek;
path = "assets-library://asset/asset.JPG?id=3B7DBB2E-1271-4D86-A5F2-A0CEEE7CC4DE&ext=JPG";
type = jpg;
};
body = "body";
isHTML = 1;
recipients = (
"[email protected]"
);
subject = Ladunek;
},
9
)
This is the invoking code :
.then((data, path) => {
console.log(data)
console.log(data.path)
Mailer.mail({
subject: 'Ladunek',
recipients: ['[email protected]'],
body: 'body',
isHTML: true, // iOS only, exclude if false
attachment: {
path: data.path, // The absolute path of the file from which to read data.
type: 'jpg', // Mime Type: jpg, png, doc, ppt, html, pdf
name: 'Ladunek', // Optional: Custom filename for attachment
}
}, (error, event) => {
if(error) {
AlertIOS.alert('Error', 'Could not send mail. Please send a mail to [email protected]');
}
});
})
Is the path invalid? Or might it be something else.
Answer is here http://stackoverflow.com/questions/38141637/react-native-send-photo-per-mail/38182998#38182998
Can we send a video as an attachment?
The answer @anton6 links to requires react-native-camera, but I'm trying to use this with react-native-image-picker and it's failing on iOS. I submitted a question on stack overflow.
https://stackoverflow.com/questions/47086300/attach-image-to-email-in-react-native
But the fundamental issue seems to be that I'm getting back a uri value that looks like this (doesn't work as the full path)...
file://var/mobile/Containers/Data/Application/983938D-5304-463C-BD05-D033E55F5BEB/Documents/images/224CA6DD-5299-48C3-A7CF-0B645004535F.jpg
Instead of something that looks like this
/Users/anton/Library/Developer/CoreSimulator/Devices/9A15F203-9A58-41C5-A4FC-EA25FAAE92BD/data/Containers/Data/Application/79FF93F9-BA89-4F4C-8809-277BEECD447D/Documents/EFFF0ECE-4063-4FE5-984E-E76506788350.jpg
which would apparently work. If anyone has a clue how to resolve this, I would appreciate it.
UPDATE
I have a working example implementation here (geirman/react-native-photo-emailer) for anyone interested. It's dated, but I expect it would still work
+1