flutter - Flutter 邮件程序正在发送重复的电子邮件,同时发送两封
问题描述
我必须构建一个具有发送电子邮件功能的应用程序,我决定使用邮件程序。但是在测试之后,我收到了两封相同的电子邮件,我又向 cc 发送了一封电子邮件,该电子邮件也收到了两封电子邮件。有没有办法让我的应用程序只发送一封电子邮件而不是两封?
void _mailer() async {
String username = '**@gmail.com';
String password = '**';
final smtpServer = gmail(username, password);
final message = Message()
..from = Address(username, 'Your name')
..recipients.add('**@outlook.com')
..ccRecipients.add('**@yahoo.com')
..subject = 'Test Dart Mailer library :: :: ${DateTime.now()}'
..text = 'This is the plain text.\nThis is line 2 of the text part.'
..attachments = attachments;
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}');
}
}
var connection = PersistentConnection(smtpServer);
await connection.send(message);
await connection.close();
}
解决方案
这个函数似乎发送了 1 封电子邮件:
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}');
}
}
这 3 行代码正在发送第二封电子邮件:
var connection = PersistentConnection(smtpServer);
await connection.send(message);
await connection.close();
所以我刚刚删除了最后 3 行代码,现在我的应用只发送一封电子邮件
推荐阅读
- javascript - Mongoose Group 以 15 秒为周期计数
- oop - 每次创建不同类的新对象时都会覆盖它
- python - 如何让 pandas read_csv 忽略部分引用值之间的分隔符?
- apache-kafka - 在集群启动并运行后向 __consumer_offsets 主题添加分区有什么副作用吗?
- batch-file - 批处理文件中的数学
- java - 为什么我的 FileReader 没有从 .txt 文件中输出代码?
- python - Python 3 - 从字典列表中获取关键错误
- html - Socket IO 400 网页上的错误请求
- python - 不可迭代值 self.hand 在迭代上下文中使用
- ajax - 我可以在提交表格之前请求表格的数据吗?烧瓶