メインコンテンツまでスキップ

メール (SMTP)

SMTP サーバーを Squid に接続し、AI agents と backend code からメールを送信する

Mail connector の機能

Mail connector を使用すると、Squid application は任意の SMTP サーバーを通じてメールを送信できます。

  • Mail connector に接続された AI agents は、ユーザーに代わってメールを作成して送信できます。たとえば、「レポートをチームにメールで送って」などです。
  • Backend code は、添付ファイル付きのメールを含め、プログラムによってメールを送信できます。

この connector は、標準的な SMTP provider であればどれでも動作します。スロットリングと送信クォータは、SMTP provider によって管理されます。

Squid application に Mail connector を追加する

  1. Squid ConsoleConnectors タブに移動します。

  2. Available Connectors をクリックします。

  3. Mail connector を見つけ、Add Connector を選択します。

  4. 次の設定情報を指定します。

Connector ID: コード内で connector を一意に識別する文字列。

SMTP Host: smtp.example.com など、SMTP サーバーのホスト名。プロトコルプレフィックスは含めないでください。

SMTP Port: 25、465、587 など、SMTP サーバーのポート番号。

SMTP Username: SMTP サーバーで認証するためのユーザー名。

SMTP Password: SMTP サーバーで認証するためのパスワード。パスワードは Squid secret として安全に保存されます。メール provider がアプリ固有のパスワードを使用する場合は、ここでそれを使用します。

SMTP Encryption: SMTP サーバーに接続するときに使用する暗号化方式: tls (default)、ssl、または none

SMTP From Address: 送信リクエストで送信者が指定されていない場合に、送信者として表示されるメールアドレス。

application で Mail connector を使用する

No-code Studio

  1. Squid ConsoleStudio タブに移動します。

  2. Create AI Agent をクリックします。

  3. "assistant-agent" や "This agent can send emails on the user's behalf" などの agent IDdescription を指定します。

  4. Add Abilities をクリックします。

  5. Mail エントリを展開し、先ほど作成した Mail connector を選択します。

  6. agent がこの connection をどのように使用すべきかについて、"Call this when the user asks to send an email." などの説明を入力します。

  7. Test をクリックし、自分宛てにテストメールを送るよう agent に依頼してみます。

Squid SDK を使用する

Squid SDK で AI agent を作成している場合は、ask() 関数の connectedIntegrations オプションに追加して Mail connector を接続します。

await this.squid
.ai()
.agent('AGENT_ID')
.ask('Send a summary of this conversation to team@example.com', {
connectedIntegrations: [
{
integrationId: 'MAIL_CONNECTOR_ID',
integrationType: 'mail',
description: 'Call this connector to send emails',
},
],
});

backend code からメールを送信する

プログラムによる送信(AI agent tool では使用できない添付ファイルを含む)を行うには、@squidcloud/mail-client package をインストールし、Squid backend から呼び出します。

npm install @squidcloud/mail-client
import { SquidMailClient } from '@squidcloud/mail-client';

const mail = new SquidMailClient(this.squid);

await mail.sendMail({
integrationId: 'MAIL_CONNECTOR_ID',
to: 'recipient@example.com',
subject: 'Monthly report',
body: '<h1>Report</h1><p>See the attached PDF.</p>',
html: true,
attachments: [
{
filename: 'report.pdf',
content: base64EncodedPdf,
encoding: 'base64',
},
],
});

リクエストで from が省略された場合、connector は設定済みの SMTP From Address を使用します。各添付ファイルは、inline content または backend 上のファイルへの path のいずれかを指定しますが、両方は指定できません。

注記

メール送信には、executablescheduler、または trigger などの privileged backend context が必要です。認証されていない client-side calls は拒否されます。