Ars*_*san 5 flutter flutter-dependencies flutter-web
我正在构建一个颤振网络我必须通过电子邮件将表单数据发送到我的 Gmail 电子邮件地址,我该怎么办。请帮我。我有用户 "mailer 3.0.4" 和 flutter_email_sender: ^2.2.2 但他们都没有工作......这是我的代码:
// Perform login or signup
Future<void> _validateAndSubmitForInformationForm() async {
print('1');
final MailOptions mailOptions = MailOptions(
body: 'a long body for the email <br> with a subset of HTML',
subject: 'the Email Subject',
recipients: ['bc160201844@vu.edu.pk'],
isHTML: true,
bccRecipients: ['bc160201844@vu.edu.pk'],
ccRecipients: ['bc160201844@vu.edu.pk'],
// attachments: [
// 'path/to/image.png',
// ],
);
print('3');
await FlutterMailer.send(mailOptions);
print('2');
}
Run Code Online (Sandbox Code Playgroud)
您可以使用 SendGrid 之类的工具从 flutter mobile 发送电子邮件,其中包含以下内容:对于格式错误表示抱歉。
import 'package:http/http.dart' as http;
class SendGridUtil {
static sendRegistrationNotification(String email) async {
Map<String, String> headers = new Map();
headers["Authorization"] =
"Bearer $$$SENDGRIDAPIKEY$$$";
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\": \"jerrod@liftaixxx.com\"\n },\n {\n \"email\": \"darran@gmailxxx.com\"\n }\n ]\n }\n ],\n \"from\": {\n \"email\": \"app@liftaixxx.com\"\n },\n \"subject\": \"New user registration\",\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}');
}
}
Run Code Online (Sandbox Code Playgroud)
要从 flutter web 发送电子邮件,您可以使用类似 firebase 云功能的功能 - 这是在 firebase auth 中创建新用户时执行的功能:
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
const sgMail = require('@sendgrid/mail')
admin.initializeApp(functions.config().firebase);
exports.sendWelcomeEmail = functions.auth.user().onCreate(user => {
console.log("User with email created: " + user.email);
sgMail.setApiKey("$$$SENDGRIDKEY$$$");
const liftAiMsg = {
to: 'jerrod@liftaixxx.com',
from: 'app@liftaixxx.com',
subject: 'New user created',
text: 'New user created with email: ' +user.email,
html: "<strong>New user created with email: "+user.email+"</strong>",
};
sgMail.send(liftAiMsg);
const customerMsg = {
to: user.email,
from: 'app@liftaixxx.com',
subject: 'Welcome to LiftAI',
text: 'Welcome to LiftAI',
html: '<strong>Welcome to LiftAI!</strong>',
};
sgMail.send(customerMsg);
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5131 次 |
最近记录: |