如何解决Flutter Mailer发送重复的电子邮件,两个同时
我必须构建一个具有发送电子邮件功能的应用程序,所以我决定使用mailer。但是在测试之后,我收到了两封相同的电子邮件,然后又向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}');
}
}
这三行代码正在发送第二封电子邮件:
var connection = PersistentConnection(smtpServer);
await connection.send(message);
await connection.close();
所以我刚刚删除了最后三行代码,现在我的应用仅发送一封电子邮件
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。