react-native-mail
react-native-mail copied to clipboard
Question: Syntax for adding multiple attachments?
This is probably a javascript newbie problem. What would syntax look like for multiple email file attachments?
I tried the following which is apparently not correct javascript. My goal is to iterate through my fileAttachmentList array and build the Mailer.mail attachment object.
Mailer.mail({
subject: subjectText,
recipients: ['[email protected]'],
body: bodyText,
attachment: {
path: this.state.fileAttachmentList[0].fileNamePath,
type: this.state.fileAttachmentList[0].fileMimeType,
name: this.state.fileAttachmentList[0].fileName,
},
{
path: this.state.fileAttachmentList[1].fileNamePath,
type: this.state.fileAttachmentList[1].fileMimeType,
name: this.state.fileAttachmentList[1].fileName,
}
}, (error, event) => {
if(error) {
Alert.alert('Error', 'Could not send mail');
}
});
Thank you very much for sharing your work on such a great react-component !
After browsing https://github.com/chirag04/react-native-mail/blob/master/RNMail/RNMail.m I think the answer is that only a single file attachment is currently supported.
I think the easiest method might be to pass an 'attachments' array containing only file path name of each file. Then in the Objective-C code, strip file name from path, and determine mime type from file extension.
This is not ideal, but I have no idea how to pass an array of attachment objects into Objective-C. Maybe I can find an example someplace.
I made fork that supports multiple attachments. In process of adding Android support for multiple attachments as well.
I also have HTML email for Android working but have not checked it in yet.
https://github.com/esutton/react-native-mail