Я пытаюсь отправить форму из приложения флаттера на мою электронную почту автоматически, когда пользователь отправляет форму. Вот код:
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:url_launcher/url_launcher.dart';
import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
.
.
.
.
.
.
void mailer () async {
String username = 'some@gmail.com';
String password = '****************************';
final smtpServer = gmail(username, password);
// Use the SmtpServer class to configure an SMTP server:
// final smtpServer = SmtpServer('smtp.domain.com');
// See the named arguments of SmtpServer for further configuration
// options.
// Create our message.
final message = Message()
..from = Address(username, 'Ahmad Shaker')
..recipients.add('some@hotmail.com')
..ccRecipients.addAll(['destCc1@example.com', 'destCc2@example.com'])
..bccRecipients.add(Address('bccAddress@example.com'))
..subject = 'Test Dart Mailer library'
..text = 'This is the plain text.\nThis is line 2 of the text part.'
..html = "<h1>Test</h1>\n<p>Hey! Here's some HTML content</p>";
try {
final sendReport = await send(message, smtpServer);
print('Message sent: ' + sendReport.toString());
} on MailerException catch (e) {
print('Message not sent.');
for (var p in e.problems) {
print('Problem: ${p.code}: ${p.msg}');
}
}
// DONE
// Let's send another message using a slightly different syntax:
//
// Addresses without a name part can be set directly.
// For instance `..recipients.add('destination@example.com')`
// If you want to display a name part you have to create an
// Address object: `new Address('destination@example.com', 'Display name part')`
// Creating and adding an Address object without a name part
// `new Address('destination@example.com')` is equivalent to
// adding the mail address as `String`.
final equivalentMessage = Message()
..from = Address(username, 'Ahmad Eshbialat')
..recipients.add(Address('ahmad0shaker@gmail.com'))
..ccRecipients.addAll([Address('destCc1@example.com'), 'destCc2@example.com'])
..bccRecipients.add('bccAddress@example.com')
..subject = 'Test Dart Mailer library :: ? :: ${DateTime.now()}'
..text = 'This is the plain text.\nThis is line 2 of the text part.'
..html = "<h1>Test</h1>\n<p>Hey! Here's some HTML content</p>";
final sendReport2 = await send(equivalentMessage, smtpServer);
// Sending multiple messages with the same connection
//
// Create a smtp client that will persist the connection
var connection = PersistentConnection(smtpServer);
// Send the first message
await connection.send(message);
// send the equivalent message
await connection.send(equivalentMessage);
// close the connection
await connection.close();
}
Это дает мне эту ошибку:
I / флаттер (6901): сообщение не отправлено. E / flutter (6901): [ОШИБКА: flutter / lib / ui / ui_dart_state.cc (144)] Необработанное исключение: неверное имя пользователя / пароль / учетные данные E / flutter (6901): # 0 _doAuthentication (пакет: mailer / src / smtp)/smtp_client.dart:105:5) E / flutter (6901): E / flutter (6901): # 1 connect (пакет: mailer / src / smtp / smtp_client.dart: 135: 11) E / flutter (6901):E / flutter (6901): # 2 send (package: mailer / src / smtp / mail_sender.dart: 93: 26) E / flutter (6901): # 3 _AsyncAwaitCompleter.start (dart: async-patch / async_patch.dart:43: 6) E / flutter (6901): отправка # 4 (пакет: mailer / src / smtp / mail_sender.dart: 90: 24) E / flutter (6901): отправитель № 5 (пакет: Clowns_in_Amman / main.dart:991: 29) E / flutter (6901): # 6 _asyncErrorWrapperHelper. (dart: async-patch / async_patch.dart: 78: 45) E / flutter (6901): # 7 _rootRunBinary (dart: async / zone.dart: 1144: 38) E / flutter (6901): # 8 _CustomZone.runBinary(dart: async / zone.dart: 1037: 19) E / flutter (6901): # 9 _FutureListener.handleError (dart: async / future_impl.dart: 151: 20) E / flutter (6901): # 10 Future._propagateToListeners.handleError (dart: async / future_impl.dart: 690: 47) E / flutter (6901): # 11 Future._propagateToListeners (dart: async / future_impl.dart: 711: 24) E / flutter (6901): # 12 Future._completeError (dart: async / future_impl.dart: 530: 5) E / flutter (6901): # 13 _AsyncAwaitCompleter.completeError (dart: async-patch / async_patch.dart: 36: 15) E / flutter (6901): #14 send (package: mailer / src / smtp / mail_sender.dart) E / flutter (6901): # 15 _asyncErrorWrapperHelper. (dart: async-patch / async_patch.dart: 78: 45) E / flutter (6901): # 16 _rootRunBinary (dart: async / zone.dart: 1144: 38) E / flutter (6901): # 17 _CustomZone.runBinary(dart: async / zone.dart: 1037: 19) E / flutter (6901): # 18 _FutureListener.handleError (dart: async / future_impl.dart: 151: 20) E / flutter (6901): # 19 Future._propagateToListeners.handleError (dart: async / future_impl.dart: 690: 47) E / flutter (6901): # 20 Future._propagateToListeners (dart: async / future_impl.dart: 711: 24) E / flutter (6901): # 21 Future._completeError (dart: async / future_impl.dart: 530: 5) E / flutter (6901): # 22 _AsyncAwaitCompleter.completeError (dart: async-patch / async_patch.dart: 36: 15) E / flutter (6901): #23 connect (пакет: mailer / src / smtp / smtp_client.dart) E / flutter (6901): # 24 _asyncThenWrapperHelper. (dart: async-patch / async_patch.dart: 71: 64)
E / flutter (6901): # 25 _rootRunUnary (dart: async / zone.dart: 1132: 38) E / flutter (6901): # 26_CustomZone.runUnary (dart: async / zone.dart: 1029: 19) E / flutter (6901): # 27 _FutureListener.handleValue (dart: async / future_impl.dart: 137: 18) E / flutter (6901): # 28Future._propagateToListeners.handleValueCallback (dart: async / future_impl.dart: 678: 45)
E / flutter (6901): # 29 Future._propagateToListeners (дарт: async / future_impl.dart: 707: 32) E / flut (6901): # 30 Future._completeWithValue (дротик: async / future_impl.dart: 522: 5) E / flutter (6901): # 31 _AsyncAwaitCompleter.complete (дарт: async-patch / async_patch.dart: 30: 15) E /flutter (6901): # 32 _completeOnAsyncReturn (dart: async-patch / async_patch.dart: 288: 13) E / flutter (6901): # 33 Connection.close (пакет: mailer / src / smtp / connection.dart) E /трепетание (6901): # 34 _asyncThenWrapperHelper. (dart: async-patch / async_patch.dart: 71: 64)
E / flutter (6901): # 35 _rootRunUnary (dart: async / zone.dart: 1132: 38) E / flutter (6901): # 36_CustomZone.runUnary (dart: async / zone.dart: 1029: 19)E / flutter (6901): # 37 _FutureListener.handleValue (дротик: async / future_impl.dart: 137: 18) E / flutter (6901): # 38 Future._propagateToListeners.handleValueCallback (дарт: async / future_impl.dart: 678:45) E / flutter (6901): # 39 Future._propagateToListeners (dart: async / future_impl.dart: 707: 32) E / flutter (6901): # 40 Future._addListener. (dart: async / future_impl.dart: 387: 9) E / flutter (6901): # 41 _microtaskLoop (dart: async / schedule_microtask.dart: 41: 21) E / flutter (6901): # 42 _startMicrotaskLoop (dart: async/schedule_microtask.dart:50:5) E / flutter (6901):
Я уверен, что имя пользователя и пароль верны.