'Sending Email with Flutter using SMTP
I'm new on Flutter, I'm still studying. I want to send email using my SMTP provider but I'm not able to. Can you help me??
Here my function:
import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server.dart';
void send_email(String strEmail) async {
String smtpServerName = 'smtps.xxxxx.it';
int smtpPort = 465;
String smtpUserName = '[email protected]';
String smtpPassword = 'mypassword';
final smtpServer = SmtpServer(
smtpServerName,
port: smtpPort,
ssl: true,
ignoreBadCertificate: false,
allowInsecure: false,
username: smtpUserName,
password: smtpPassword,
);
final message = Message()
..from = Address("[email protected]", "My App")
..recipients.add(strEmail)
..subject = 'Hello'
..html = 'Hi, how are you?';
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}');
}
}
}
When I try to debug it , it doesn't work and it gives me those errors.
CHROME EMULATOR ERROR:
Error: Unsupported operation: RawSocket constructor
at Object.throw_ [as throw] (http://localhost:52995/dart_sdk.js:5037:11)
at Function.connect (http://localhost:52995/dart_sdk.js:55997:17)
.......
ANDROID EMULATOR ERROR:
E/flutter (12712): CERTIFICATE_VERIFY_FAILED: self signed certificate in certificate chain(handshake.cc:359))
E/flutter (12712): #0 _SecureFilterImpl._handshake (dart:io-patch/secure_socket_patch.dart:101:69)
E/flutter (12712): #1 _SecureFilterImpl.handshake (dart:io-patch/secure_socket_patch.dart:143:25)
E/flutter (12712): #2 _RawSecureSocket._secureHandshake (dart:io/secure_socket.dart:794:54)
E/flutter (12712): #3 _RawSecureSocket._tryFilter (dart:io/secure_socket.dart:924:19)
E/flutter (12712): <asynchronous suspension>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|