是否可以在不打开默认电子邮件应用程序的情况下发送电子邮件? (直接地)
我用了两个插件。但两者都是打开默认应用程序。
Using flutter_email_sender
plugin
final Email email = Email(
body:
'Vendor Name = ${value.title} ${value.ownerName}<br>\nCompany Name = ${value.displayName}',
subject: 'New Vendor Registed',
recipients: ['[email protected] /cdn-cgi/l/email-protection'],
isHTML: true,
);
await FlutterEmailSender.send(email)
Using url_launcher
plugin
final String _email = 'mailto:' +
'bhanukaisur[email protected] /cdn-cgi/l/email-protection'+
'?subject=' +
'New Vendor Registered' +
'&body=' +
'Vendor Name =${value.title} ${value.ownerName}\n' +
'Company Name = ${value.displayName}';
await FlutterEmailSender.send(email);
您可以直接使用 flutter 应用程序发送消息发送网格 API https://sendgrid.com/和http post请求。
在这里,您需要将 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\": \"[email protected] /cdn-cgi/l/email-protection\"\n },\n {\n \"email\": \"[email protected] /cdn-cgi/l/email-protection\"\n }\n ]\n }\n ],\n \"from\": {\n \"email\": \"[email protected] /cdn-cgi/l/email-protection\"\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}');
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)