flutter - 发送直接电子邮件到电子邮件地址 Flutter
问题描述
我希望我的应用程序直接向特定的电子邮件地址发送消息我在 onPress sendEmail('example1@gmail.com', 'example1password') 中使用了此功能
void sendEmail(username, password) async {
SmtpServer smtpServer = mailgun(username, password);
final message = new Message()
..from = new Address(username, 'My App')
..recipients.add('example2@gmail.com')
..subject = 'New User Register'
..text = 'New user want activate code';
try {
GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: <String>[
'email',
'https://www.googleapis.com/auth/gmail.send',
],
);
// Signing in
final account = await _googleSignIn.signIn();
if (account == null) {
print("User didn't authorize");
}
final auth = await account!.authentication;
// Creating SMTP server from the access token
smtpServer = gmailSaslXoauth2(username ,auth.accessToken!);
} on PlatformException catch (e) {
print(e);
}
try {
final sendReport = await send(message, smtpServer);
print('Message sent: ' + sendReport.toString()); //print if the email is sent
} on MailerException catch (e) {
print('Message not sent. \n'+ e.toString()); //print if the email is not sent
btnState = ButtonState.fail;
// e.toString() will show why the email is not sending
}
}
当我按下按钮时,函数调用并显示谷歌对话框 - (我现在不知道为什么这个对话框出现可能是为了注册?) - 在选择帐户后使用我的帐户显示这个
V/PhoneWindow(27336): DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@d289c7, this = DecorView@6897bf4[MainActivity]
I/flutter (27336): PlatformException(network_error, com.google.android.gms.common.api.ApiException: 7: , null, null)
D/Surface (27336): Surface::disconnect(this=0x7251f0d000,api=1)
D/Surface (27336): Surface::connect(this=0x7251f0d000,api=1)
D/mali_winsys(27336): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
D/Surface (27336): Surface::setBufferCount(this=0x7251f0d000,bufferCount=3)
V/PhoneWindow(27336): DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@672a92b, this = DecorView@3b6579c[SignInHubActivity]
D/Surface (27336): Surface::disconnect(this=0x72521d0000,api=1)
D/View (27336): [Warning] assignParent to null: this = DecorView@3b6579c[SignInHubActivity]
E/flutter (27336): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: SocketException: Failed host lookup: 'smtp.mailgun.org' (OS Error: No address associated with hostname, errno = 7)
E/flutter (27336): #0 _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:677:35)
E/flutter (27336): #1 _NativeSocket.connect (dart:io-patch/socket_patch.dart:914:12)
E/flutter (27336): #2 _RawSocket.connect (dart:io-patch/socket_patch.dart:1668:26)
E/flutter (27336): #3 RawSocket.connect (dart:io-patch/socket_patch.dart:21:23)
E/flutter (27336): #4 Socket._connect (dart:io-patch/socket_patch.dart:1883:22)
E/flutter (27336): #5 Socket.connect (dart:io/socket.dart:724:21)
E/flutter (27336): #6 Connection.connect (package:mailer/src/smtp/connection.dart:135:24)
E/flutter (27336): #7 connect (package:mailer/src/smtp/smtp_client.dart:116:13)
E/flutter (27336): #8 send (package:mailer/src/smtp/mail_sender.dart:94:26)
E/flutter (27336): #9 Manage.sendEmail (package:accounting/Custom/Manage/manage.dart:147:34)
E/flutter (27336): <asynchronous suspension>
E/flutter (27336):
请帮助我非常渴望解决这个问题。
解决方案
推荐阅读
- java - 查询返回 (rs.next() == false)。已填充表,已连接数据库
- javascript - React Native:有没有办法将图标“共享”添加到我的抽屉而不是按钮?
- python-3.x - openpyxl 遍历所有行并取消合并单元格
- javascript - 消息:“http://localhost/post.php 的 Http 失败响应:0 未知错误”和 POST http://localhost/post.php net::ERR_FAILED
- python - 如何在 python Keras 中实现自定义指标“负预测值”?
- java - 在相同颜色背景上滚动时如何更改 textView 颜色?
- java - 如何转换 ArrayList
到数组列表 ? - javascript - 在 ejs 中动态设置 data-id 的值
- xunit - AutoFixture 可以为作为该类属性的每个可能的枚举创建一个对象列表吗?
- python - sklearn.linear_model.Lasso 可以识别熊猫数据框中的分类数据类型吗?