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

How to send to a list of recipients using an array value

Open danneu2s1fa opened this issue 7 years ago • 0 comments

Hi,

Can you please explain the correct code to pass an array with a series of name and email addresses to react-native-mail? Thanks in advance!

When passing an array with two items, each with names and email addresses, the email generated from react-native-mail contains only a single recipient with the email address from the second item in the array, and a malformed name. Can anyone explain why this fails?

_handleEmail () { let listNamesAndEmails = _.map(this.props.list_to_email, function(o) { return '${o.first_name} ${o.last_name} <${o.email}>' ; });
console.log ('listNamesAndEmails: ' + listNamesAndEmails); try {
Mailer.mail({ subject: 'Placeholder subject', recipients: [${listNamesAndEmails}], body: 'Placeholder content', isHTML: true, }, (error, event) => { Alert.alert( error, event, [ {text: 'Ok', onPress: () => console.log('OK: Email Error Response')}, {text: 'Cancel', onPress: () => console.log('CANCEL: Email Error Response')} ], { cancelable: true } ); }); } catch (error){ console.log('_handleEmail error: ' + error) } }

The console output shows that the array is formatted correctly, as the same string works in the example that follows.

2018-08-17 16:08:46.350390-0400 appTest[457:85096] listNamesAndEmails: 'A1f A1l [email protected]','A2f A2l [email protected]'

2018-08-17 16:08:46.461430-0400 appTest[457:84929] [MC] Filtering mail sheet accounts for bundle ID: com.test.appTest, source account management: 1 2018-08-17 16:08: com.test.appTest-0400 appTest[457:84929] [MC] Filtering mail sheet accounts for bundle ID: com.test.appTest, source account management: 1

The same values, entered as values into recipients below works. Can anyone explain why the above fails, and the following generates an email with 2 recipients from react-native-mail?

_handleEmail () {

try { Mailer.mail({ subject: 'Placeholder subject', recipients: ['First1 Last1 [email protected]', 'First2 Last2 [email protected]'], body: 'Placeholder content', isHTML: true, }, (error, event) => { Alert.alert( error, event, [ {text: 'Ok', onPress: () => console.log('OK: Email Error Response')}, {text: 'Cancel', onPress: () => console.log('CANCEL: Email Error Response')} ], { cancelable: true } ); }); } catch (error){ console.log('_handleEmail error: ' + error) }
}

danneu2s1fa avatar Aug 17 '18 20:08 danneu2s1fa