@@ -41,7 +41,7 @@ + (BOOL)requiresMainQueueSetup
4141 NSString *subject = [RCTConvert NSString: options[@" subject" ]];
4242 [mail setSubject: subject];
4343 }
44-
44+
4545 bool *isHTML = NO ;
4646
4747 if (options[@" isHTML" ]){
@@ -57,7 +57,7 @@ + (BOOL)requiresMainQueueSetup
5757 NSArray *recipients = [RCTConvert NSArray: options[@" recipients" ]];
5858 [mail setToRecipients: recipients];
5959 }
60-
60+
6161 if (options[@" ccRecipients" ]){
6262 NSArray *ccRecipients = [RCTConvert NSArray: options[@" ccRecipients" ]];
6363 [mail setCcRecipients: ccRecipients];
@@ -67,49 +67,52 @@ + (BOOL)requiresMainQueueSetup
6767 NSArray *bccRecipients = [RCTConvert NSArray: options[@" bccRecipients" ]];
6868 [mail setBccRecipients: bccRecipients];
6969 }
70-
71- if (options[@" attachment" ] && options[@" attachment" ][@" path" ] && options[@" attachment" ][@" type" ]){
72- NSString *attachmentPath = [RCTConvert NSString: options[@" attachment" ][@" path" ]];
73- NSString *attachmentType = [RCTConvert NSString: options[@" attachment" ][@" type" ]];
74- NSString *attachmentName = [RCTConvert NSString: options[@" attachment" ][@" name" ]];
75-
76- // Set default filename if not specificed
77- if (!attachmentName) {
78- attachmentName = [[attachmentPath lastPathComponent ] stringByDeletingPathExtension ];
79- }
80-
81- // Get the resource path and read the file using NSData
82- NSData *fileData = [NSData dataWithContentsOfFile: attachmentPath];
83-
84- // Determine the MIME type
85- NSString *mimeType;
86-
87- /*
88- * Add additional mime types and PR if necessary. Find the list
89- * of supported formats at http://www.iana.org/assignments/media-types/media-types.xhtml
90- */
91- if ([attachmentType isEqualToString: @" jpg" ]) {
92- mimeType = @" image/jpeg" ;
93- } else if ([attachmentType isEqualToString: @" png" ]) {
94- mimeType = @" image/png" ;
95- } else if ([attachmentType isEqualToString: @" doc" ]) {
96- mimeType = @" application/msword" ;
97- } else if ([attachmentType isEqualToString: @" ppt" ]) {
98- mimeType = @" application/vnd.ms-powerpoint" ;
99- } else if ([attachmentType isEqualToString: @" html" ]) {
100- mimeType = @" text/html" ;
101- } else if ([attachmentType isEqualToString: @" csv" ]) {
102- mimeType = @" text/csv" ;
103- } else if ([attachmentType isEqualToString: @" pdf" ]) {
104- mimeType = @" application/pdf" ;
105- } else if ([attachmentType isEqualToString: @" vcard" ]) {
106- mimeType = @" text/vcard" ;
107- } else if ([attachmentType isEqualToString: @" json" ]) {
108- mimeType = @" application/json" ;
109- } else if ([attachmentType isEqualToString: @" zip" ]) {
110- mimeType = @" application/zip" ;
111- } else if ([attachmentType isEqualToString: @" text" ]) {
112- mimeType = @" text/*" ;
70+
71+ if (options[@" attachments" ]){
72+ NSArray *attachments = [RCTConvert NSArray: options[@" attachments" ]];
73+
74+ for (NSDictionary *attachment in attachments) {
75+ if (attachment[@" path" ] && attachment[@" type" ]) {
76+ NSString *attachmentPath = [RCTConvert NSString: attachment[@" path" ]];
77+ NSString *attachmentType = [RCTConvert NSString: attachment[@" type" ]];
78+ NSString *attachmentName = [RCTConvert NSString: attachment[@" name" ]];
79+
80+ // Set default filename if not specificed
81+ if (!attachmentName) {
82+ attachmentName = [[attachmentPath lastPathComponent ] stringByDeletingPathExtension ];
83+ }
84+ // Get the resource path and read the file using NSData
85+ NSData *fileData = [NSData dataWithContentsOfFile: attachmentPath];
86+
87+ // Determine the MIME type
88+ NSString *mimeType;
89+
90+ /*
91+ * Add additional mime types and PR if necessary. Find the list
92+ * of supported formats at http://www.iana.org/assignments/media-types/media-types.xhtml
93+ */
94+ if ([attachmentType isEqualToString: @" jpg" ]) {
95+ mimeType = @" image/jpeg" ;
96+ } else if ([attachmentType isEqualToString: @" png" ]) {
97+ mimeType = @" image/png" ;
98+ } else if ([attachmentType isEqualToString: @" doc" ]) {
99+ mimeType = @" application/msword" ;
100+ } else if ([attachmentType isEqualToString: @" ppt" ]) {
101+ mimeType = @" application/vnd.ms-powerpoint" ;
102+ } else if ([attachmentType isEqualToString: @" html" ]) {
103+ mimeType = @" text/html" ;
104+ } else if ([attachmentType isEqualToString: @" csv" ]) {
105+ mimeType = @" text/csv" ;
106+ } else if ([attachmentType isEqualToString: @" pdf" ]) {
107+ mimeType = @" application/pdf" ;
108+ } else if ([attachmentType isEqualToString: @" vcard" ]) {
109+ mimeType = @" text/vcard" ;
110+ } else if ([attachmentType isEqualToString: @" json" ]) {
111+ mimeType = @" application/json" ;
112+ } else if ([attachmentType isEqualToString: @" zip" ]) {
113+ mimeType = @" application/zip" ;
114+ } else if ([attachmentType isEqualToString: @" text" ]) {
115+ mimeType = @" text/*" ;
113116 } else if ([attachmentType isEqualToString: @" mp3" ]) {
114117 mimeType = @" audio/mpeg" ;
115118 } else if ([attachmentType isEqualToString: @" wav" ]) {
@@ -122,12 +125,12 @@ + (BOOL)requiresMainQueueSetup
122125 mimeType = @" audio/ogg" ;
123126 } else if ([attachmentType isEqualToString: @" xls" ]) {
124127 mimeType = @" application/vnd.ms-excel" ;
128+ }
129+ [mail addAttachmentData: fileData mimeType: mimeType fileName: attachmentName];
130+ }
125131 }
126-
127- // Add attachment
128- [mail addAttachmentData: fileData mimeType: mimeType fileName: attachmentName];
129132 }
130-
133+
131134 UIViewController *root = [[[[UIApplication sharedApplication ] delegate ] window ] rootViewController ];
132135
133136 while (root.presentedViewController ) {
0 commit comments