Prantik Mondal
Prantik Mondal

Reputation: 493

My react native android app got crashed when loggedin user trying to replay any mail for first time using react-native-mailcore library

I am using react-native-mailcore library to reply mail. As per the instruction on that library doc, i am doing smtp login before calling MailCore.sendMail. From second time reply mail is working fine with same code as well as For compose mail i am using same code to send mail. It is working fine for that case also. My code is given bellow.

import MailCore from 'react-native-mailcore';
var LocalStorage = require('react-native-local-storage');

sendMail = async () => {
    let user = await LocalStorage.get('user');
    await MailCore.loginSmtp({
      hostname: 'smtp.gmail.com',
      port: 465,
      username: user.email,
      password: user.password,
    }).catch(error => ToastAndroid.show(error,ToastAndroid.LONG))
   // All the values from the state are coming correctly
    let subject = this.state.subject || '(No Subject)';
    let body = this.state.compose + this.state.body || '';
    let from = {
      addressWithDisplayName : this.state.name,
      mailbox: this.state.user,
    }
    let to = {[this.state.to] : 'to labels'};

    // App crashed here while called sendMail

    await MailCore.sendMail({
      headers:{
        isEncrypted: 'true',
      },
      from:from,
      to:to,
      subject:subject,
      body,  
    }).then(()=>{
        this.goBack(); //navigating to main page after success
        ToastAndroid.show("sending...",ToastAndroid.SHORT);
    }).catch(err => ToastAndroid.show(err,ToastAndroid.LONG));
  }

Upvotes: 0

Views: 223

Answers (0)

Related Questions