gpt4 book ai didi

flutter - 如何在不打开Flutter的默认电子邮件应用程序的情况下发送邮件?

转载 作者:行者123 更新时间:2023-12-03 03:09:42 25 4
gpt4 key购买 nike

是否可以在不打开默认电子邮件应用程序的情况下发送电子邮件? (直)
我使用了两个插件。但两者都是打开的默认应用。

使用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);

最佳答案

您可以使用sendGridApi和http post request从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}');

}

关于flutter - 如何在不打开Flutter的默认电子邮件应用程序的情况下发送邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59509092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com