gpt4 book ai didi

flutter - 如何通过 Flutter web 直接发送电子邮件

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

我正在构建一个 flutter 网络我必须通过电子邮件将表单数据发送到我的 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');
}

最佳答案

您可以使用 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}');
}
}

要从 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);


});

关于flutter - 如何通过 Flutter web 直接发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60573294/

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