extension-email
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEmail — 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 for order confirmations, notifications, and similar one-off emails.
sendServiceEmail该skill支持从后端canister发送服务及事务性邮件。可使用发送订单确认、通知及类似的一次性邮件。
sendServiceEmailBackend
后端
This component is for sending service/transactional emails.
There is the prefabricated module which cannot be modified.
mo:caffeineai-email/emailClient.mo- 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 :
sendServiceEmailmotoko
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;
};sendServiceEmailmotoko
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);
};
};
};
};