I get the following error, and I’ll include the function code below. I am using Flutter and the mailer library. For the password, I use an application-specific password.
I/flutter ( 7869): Caught MailerException: Authentication Failed (code: 535), response:
I/flutter ( 7869): < 5.7.8 Username and Password not accepted. For more information, go to
import 'dart:typed_data';
import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server.dart';
import 'dart:io';
class EmailService {
final String _username = '[email protected]';
final String _password = 'contra';
Future<void> sendEmailWithPdf(Uint8List pdfData) async {
final smtpServer = gmail(_username, _password);
// Crear un archivo temporal para almacenar el PDF
final tempFile = File('${Directory.systemTemp.path}/document.pdf');
await tempFile.writeAsBytes(pdfData);
final message = Message()
..from = Address(_username, '[email protected]')
..recipients.add('[email protected]') // Dirección de correo del destinatario
..subject = 'PDF Attachment :: 😀 :: ${DateTime.now()}'
..text = 'This is the plain text.nThis is line 2 of the text part.'
..attachments = [
FileAttachment(tempFile)..fileName = 'document.pdf',
];
try {
final sendReport = await send(message, smtpServer);
print('Message sent: ' + sendReport.toString());
} on MailerException catch (e) {
print('Message not sent.');
print('Caught MailerException: ${e.toString()}');
for (var p in e.problems) {
print('Problem: ${p.code}: ${p.msg}');
}
} finally {
// Eliminar el archivo temporal después de enviar el correo
tempFile.deleteSync();
}
thanks
vale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.