leenah Al-Mashari
leenah Al-Mashari

Reputation: 11

Mailer 6.0.1 Not sending email

I tried to use mailer to send emails to users register in my app to tell them If I accept or reject them.

this is the code:

Future sendMail(String s, String em) async {
    SmtpServer gmail(String username, String password) =>
        SmtpServer('smtp.gmail.com',
            username: '[email protected]', password: 'kfaniqjzupiuvgtj');

    final email = 'XXXXx'; //my correct email
    final smtpServer = gmail(email, 'XXX'); // password I get it from google setting using app            //password 2 auth. 
    String t = '';
    String reply = '';

    if (s == 'accepted') {
      t = ' نسعد بقبولك في تطبيق لسن كمعلم/معلمة لطلابنا المبدعين، مرحبًا بك بيننا';
      reply = 'القبول';
    } else {
      t = 'نأسف لعدم قبولك في تطبيق لسن كمعلم/معلمة لطلابنا  نعتذر منك، دمت بخير';
      reply = 'الرفض';
    }

    final msg = Message()
      ..from = Address(email, 'تطبيق لسن')
      ..recipients.add(em)
      ..subject = 'حالة حسابك في تطبيق لسن'
      ..text = t;

    try {
      await send(msg, smtpServer);
      showSnackBar('بنجاح' + reply + 'تم');
    } on MailerException catch (e) {
      print(e);
    }
  }

  void showSnackBar(String text) {
    final snackBar = SnackBar(
      content: Text(
        text,
        style: TextStyle(fontSize: 20),
      ),
      backgroundColor: Colors.green,
    );

    ScaffoldMessenger.of(context)
      ..removeCurrentSnackBar()
      ..showSnackBar(snackBar);
  }
}

Unfortunately, when I click the button which called this method nothing is sent or rcv.

here where I include called:

 ElevatedButton(
  style: ButtonStyle(
 shape: MaterialStateProperty.all<
  RoundedRectangleBorder>( RoundedRectangleBorder(borderRadius:BorderRadius.circular(50))),
  backgroundColor:MaterialStateProperty.all<Color>(Colors.green)),
 onPressed: () {update(row['userId'], "mentor");sendMail("accept", row['email']);}, child: Text("قبول")),

the code is correct, but nothing happens

Upvotes: 1

Views: 87

Answers (0)

Related Questions