react-native-mail
react-native-mail copied to clipboard
sending an email with attachments using 'react-native-mail' library works but didn't receive email
I have a React Native app (Only for IOS) and I implemented a feature where user can share a pdf file via email using the Mail app on ios devices. I used 'react-native-mail' library for this feature and it works great. However, there was one person who said that it did send an email but didn't get an email. Checked spam folder and tried everything we could to find an email. Thought it was an issue with email credentials so we tried with a brand new gmail account but still didn't get an email.
Let me explain how this library works first. You need to set up a gmail account (has to be gmail to get this library to work) in Settings on your ios device (if there are multiple gmail accounts, only the first one is used as a sender for the react-native-mail library.) Then activate mail app with this email account. Go to the app then enter a recipient then send an email with any attachments (for my case, a small pdf file.) then we get an email on the recipient gmail account!
I could be sure an email is sent because when I get the event, it says 'sent'. I tried to reproduce the issue that person had but there was no luck. Here's my code snippet below.
const sharePdf = async () => {
Mailer.mail(
{
subject: 'Assessment Report',
recipients: [currentUser.email ? currentUser.email : ''],
body: 'Assessment Report',
isHTML: true,
attachments: [
{
path: reportUri,
type: 'pdf',
name: 'Report',
},
],
},
(error, event) => {
console.log('error => ', error);
if (error === 'not_available') {
Alert.alert(
'Please add a Gmail (Google) account to your iPad',
'Go to settings > Mail > accounts > Add Account > Google',
[
{
text: 'OK',
onPress: () => console.log('OK: Email Error Response'),
},
],
{cancelable: true},
);
} else {
Alert.alert(
event,
error,
[
{
text: 'Ok',
onPress: () => console.log('OK: Email Error Response'),
},
],
{cancelable: true},
);
}
},
);
};
please help me if anyone has faced this issue or has an idea of fixing this issue..