react-native-mail icon indicating copy to clipboard operation
react-native-mail copied to clipboard

Question: Syntax for adding multiple attachments?

Open esutton opened this issue 9 years ago • 2 comments

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 !

esutton avatar Mar 17 '16 15:03 esutton

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.

esutton avatar Mar 21 '16 21:03 esutton

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

esutton avatar Jun 09 '16 13:06 esutton