extension-email

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Email — Service/Transactional

邮件 — 服务/事务性

Service/transactional email extension for Caffeine AI.
Caffeine AI提供的服务/事务性邮件扩展。

Overview

概述

This skill adds support for sending service and transactional emails from the backend canister. Use
sendServiceEmail
for order confirmations, notifications, and similar one-off emails.
该skill支持从后端canister发送服务及事务性邮件。可使用
sendServiceEmail
发送订单确认、通知及类似的一次性邮件。

Backend

后端

This component is for sending service/transactional emails.
There is the prefabricated module
mo:caffeineai-email/emailClient.mo
which cannot be modified.
  • Use the sendServiceEmail function.
  • Each recipient is sent an individual email
  • It returns a SendResult which is #ok if the email is sent successfully otherwise #err(error) with the error text.
mo
module {
  public type SendResult = {
    #ok;
    #err : Text;
  };

  public func sendServiceEmail(
    fromUsername : Text,
    recipients : [Text],
    subject : Text,
    htmlBody : Text,
  ) : async SendResult;
};
Usage for
sendServiceEmail
:
motoko
import Runtime "mo:core/Runtime";
import EmailClient "mo:caffeineai-email/emailClient";

actor {
  public func sendOrderConfirmationEmail(recipientEmailAddress : Text, username : Text, orderReference : Text) : async () {
    let result = await EmailClient.sendServiceEmail(
      "no-reply",
      [recipientEmailAddress],
      "Order " # orderReference # " confirmed",
      "Hello " # username # ",\nYour order " # orderReference # " has been confirmed. Your items will ship tomorrow.",
    );
    switch (result) {
      case (#ok) {};
      case (#err(error)) {
        Runtime.trap("Failed to send order confirmation email: " # error);
      };
    };
  };
};
该组件用于发送服务/事务性邮件。
存在预制模块
mo:caffeineai-email/emailClient.mo
,不可修改。
  • 使用sendServiceEmail函数。
  • 为每位收件人单独发送邮件
  • 返回SendResult类型结果:邮件发送成功时为#ok,失败时为#err(error)并附带错误文本。
mo
module {
  public type SendResult = {
    #ok;
    #err : Text;
  };

  public func sendServiceEmail(
    fromUsername : Text,
    recipients : [Text],
    subject : Text,
    htmlBody : Text,
  ) : async SendResult;
};
sendServiceEmail
的使用示例:
motoko
import Runtime "mo:core/Runtime";
import EmailClient "mo:caffeineai-email/emailClient";

actor {
  public func sendOrderConfirmationEmail(recipientEmailAddress : Text, username : Text, orderReference : Text) : async () {
    let result = await EmailClient.sendServiceEmail(
      "no-reply",
      [recipientEmailAddress],
      "Order " # orderReference # " confirmed",
      "Hello " # username # ",\nYour order " # orderReference # " has been confirmed. Your items will ship tomorrow.",
    );
    switch (result) {
      case (#ok) {};
      case (#err(error)) {
        Runtime.trap("Failed to send order confirmation email: " # error);
      };
    };
  };
};