是否可以在不打开默认电子邮件应用程序的情况下发送电子邮件? (直) 我使用了两个插件。但两者都是打开的默认应用。
使用flutter_email_sender
插件
final Email email = Email(
body:
'Vendor Name = ${value.title} ${value.ownerName}<br>\nCompany Name = ${value.displayName}',
subject: 'New Vendor Registed',
recipients: ['sample@gmail.com'],
isHTML: true,
);
await FlutterEmailSender.send(email)
使用url_launcher
插件
final String _email = 'mailto:' +
'bhanukaisuru96@gmail.com'+
'?subject=' +
'New Vendor Registered' +
'&body=' +
'Vendor Name =${value.title} ${value.ownerName}\n' +
'Company Name = ${value.displayName}';
await FlutterEmailSender.send(email);
答案 0 :(得分:3)
您可以直接使用sendGridApi和http发表请求从flutter应用程序发送消息。 在这里,您需要将sendGridId添加到here_your_sendGrid_id。 这是示例代码:
sendRegistrationNotification(String email) async {
Map<String, String> headers = new Map();
headers["Authorization"] =
"Bearer here_your_sendGrid_id";
headers["Content-Type"] = "application/json";
var url = 'https://api.sendgrid.com/v3/mail/send';
var response = await http.post(url,
headers: headers,
body:
"{\n \"personalizations\": [\n {\n \"to\": [\n {\n \"email\": \"yourmail@gmail.com\"\n },\n {\n \"email\": \"yourmail@gmail.com\"\n }\n ]\n }\n ],\n \"from\": {\n \"email\": \"yourmail@gmail.com\"\n },\n \"subject\": \"Test Message\",\n \"content\": [\n {\n \"type\": \"text\/plain\",\n \"value\": \"New user register: $email\"\n }\n ]\n }");
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
}
答案 1 :(得分:1)
我一直在寻找一种方法来做,终于找到了。
https://pub.dev/packages/mailer
使用上面链接中的mailer插件。它非常简单易用。 请注意,您必须将电子邮件添加为发件人邮件和密码,这样消息才能通过,并且不要将您的(发件人邮件)与收件人邮件区分开来。
答案 2 :(得分:0)