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

2024-01-09

我正在构建一个 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: ['[email protected] /cdn-cgi/l/email-protection'],
      isHTML: true,
      bccRecipients: ['[email protected] /cdn-cgi/l/email-protection'],
      ccRecipients: ['[email protected] /cdn-cgi/l/email-protection'],
//      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\": \"[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\": \"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: '[email protected] /cdn-cgi/l/email-protection',
  from: '[email protected] /cdn-cgi/l/email-protection',
  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: '[email protected] /cdn-cgi/l/email-protection',
  subject: 'Welcome to LiftAI',
  text: 'Welcome to LiftAI',
  html: '<strong>Welcome to LiftAI!</strong>',
};

sgMail.send(customerMsg);


});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何通过 Flutter web 直接发送电子邮件 的相关文章

随机推荐

  • 在 Haskell 中使用递归查找列表中的出现次数

    我有一个列表 它只能包含两种元素 Apple and Peach 我需要创建一个函数 给定一个包含这些元素的列表 该函数返回出现的次数Apple通过使用递归在列表中 这是我的尝试 data Fruit Apple Peach findFru
  • 自动将 jupyter 笔记本转换为 .py

    我知道对此有一些疑问 但我还没有发现任何足够可靠的内容 目前我正在从终端使用一个创建 py 的命令 然后将它们移动到另一个文件夹 jupyter nbconvert to script folder notebooks notebook i
  • “图像视图”的位置和大小不明确

    我试图设置 UIImageView 在故事板中没有固定的大小和宽度 我将容器的前导空间设置为大于或等于 20 将容器的顶部空间设置为大于或等于 20 将容器的尾随空间设置为大于或等于 20 并将 UICollectionView 的垂直间距
  • 将用户/密码添加到 SOAPHeader 以使用 AXIS2 进行 WebService 客户端调用

    请帮助 我正在尝试从 SOAPUI 调用 WebService 我注意到该服务需要我通过请求参数提供的用户名和密码 我注意到原始 XML 包含添加到 SOAPHeader 中的用户 密码片段 片段如下
  • div 可以有多个类吗(Twitter Bootstrap)[重复]

    这个问题在这里已经有答案了 一个div标签可以有两个类吗 我正在使用 twitter bootstrap 并且我想使用两个预定义的类 一个是一个active我想在一个类上使用dropdown toggle在导航栏中 在 html 中解决这个
  • ASP.Net 会话超时:为什么默认使用 20 分钟?

    在 ASP Net 中 默认会话超时设置为 20 分钟 为什么这样 这背后有什么具体原因吗 不应将其设置为高于 20 分钟 特殊情况除外 因为每个打开的会话都会占用内存 From MSDN 站点上的 Session Timeout http
  • 我可以控制 RealityKit 中的 Reality Composer 行为吗?

    我想使用 SwiftUI 制作一个按钮 当按下按钮时 模型将隐藏 我已经阅读了此链接中的教程 创建触发器 https developer apple com documentation realitykit creating a trigg
  • OpenGLES 中的屏幕到世界坐标转换是一项简单的任务吗?

    iPhone 上的屏幕与世界问题e 我有一个在 EAGLView 中渲染的 3D 模型 CUBE 我希望能够检测到何时触摸立方体的给定面 从任何方向角度 的中心 听起来很容易 但事实并非如此 问题 如何准确地将屏幕坐标 触摸点 与世界坐标
  • JAVAFX / WebView / WebEngine FireBugLite 或其他一些调试器?

    我正在开发一个应用程序 需要在应用程序的 WebView WebEngine 部分运行调试器 以便我可以更好地调试我的应用程序 但我在互联网上找到的注入 Firebug Lite 的代码由于某种原因无法正常工作 如果我在 Firefox 控
  • 处理来自 IOS 设备的请求时发生异常

    我正在尝试在 iOS 设备上播放视频 当我尝试玩时出现以下错误 27 Apr 2015 06 59 30 GET media 2015 04 VID 20150327 112644 mp4 HTTP 1 1 200 18 Exception
  • 未在 Blazor 服务器端应用程序中创建本地化 Cookie

    我设置了本地化Startup cs services AddLocalization options gt options ResourcesPath Resources and var supportedCultures new en U
  • 将代码从 RestSharp 转换为 HttpClient

    有人可以帮我将这个使用 RestSharp 的 ASP Net Core 示例 在我的 Web Api 中使用以使用来自 Auth0 的管理 API 转换为使用 HttpClient 的示例吗 var client new RestClie
  • 如何在Python中运行并行程序

    我有一个 python 脚本来使用 os subprocess 模块运行一些外部命令 但其中一个步骤需要花费大量时间 因此我想单独运行它 我需要启动它们 检查它们是否完成 然后执行下一个不并行的命令 我的代码是这样的 nproc 24 fo
  • 使用 PHP 保护文档

    我有一个简单的登录 访问控制系统来保护一些受限制的页面 但在这些页面内有一些需要保护的链接 即Word文档 因此 如果我将这些资源保留在 webroot 中 它们就可以通过 URL 访问 保护受限制页面内的这些资源的最佳方法是什么 我知道我
  • Activity.java 中的多个选定项 RecyclerView

    我有一个RecyclerView来自本地的数据JSON in CardView 当单击一个或某个项目时 更改所选项目的背景或突出显示 例如在 Line App 中编辑 但没有 Button 或 我需要在选定的项目上实现longpress 但
  • Aptana 配置:配置的解释器在文件系统中不存在

    标题里说的差不多了 我已经更新到最新版本了Aptana 在 Windows 上 现在我的解释器无法工作 我已经重新创建了PYTHONPATH变量 删除并重新配置python解释器Aptana 在我的项目中删除并重新创建它 仍然不起作用 它给
  • 有人知道为什么 lintr 将我的 jupyter r 内核的第一个字符串标记为红色吗?

    我刚刚在 vscode 中设置了 R 来与 Jupyter 笔记本一起使用 但它用红色标记了我的内核的第一个字符串 我收到的消息是 Failed to run diagnostics error in callr subprocess Ca
  • Openshift 将 wp-admin 重定向到 https

    在 WordPress 的常规选项中 我已将 WordPress 目录更改为 onhttp mywebsite com但 WordPress 仪表板仍处于 HTTPPS 中 导致混合内容警告 即使在 Firefox 上禁用混合内容过滤器后
  • Rails 单元测试是否应该访问数据库?

    我一直在为我的 Rails 应用程序编写测试 我使用 TestUnit 进行单元测试和功能测试 我也使用 Cucumber 进行 GUI 测试 但我发现http www dcmanges com blog rails unit record
  • 如何通过 Flutter web 直接发送电子邮件

    我正在构建一个 flutter web 我必须通过电子邮件将表单数据发送到我的 Gmail 电子邮件地址 我该怎么办 请帮我 我有用户 mailer 3 0 4 和 flutter email sender 2 2 2 但他们都没有工作 这