chirag04 / react-native-mail

A wrapper on top of MFMailComposeViewController from iOS and Mail Intent on android
MIT License
445 stars 248 forks source link

Question: Syntax for adding multiple attachments? #14

Open esutton opened 8 years ago

esutton commented 8 years ago

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: ['edward.sutton@subsite.com'],
      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 commented 8 years ago

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 commented 8 years ago

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