由于这些错误,颤动邮件发送器无法工作 [英] Flutter Mailer isn't working due to these errors
本文介绍了由于这些错误,颤动邮件发送器无法工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户提交表单时,我正在尝试将表单从Ffltter应用程序自动发送到我的电子邮件中。代码如下:
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.
This is line 2 of the text part.'
..html = "<h1>Test</h1>
<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.
This is line 2 of the text part.'
..html = "<h1>Test</h1>
<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();
}
它显示以下错误:
这篇关于由于这些错误,颤动邮件发送器无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文