Skip to content

docker composeで起動したDifyからSMTPでメール送信する

先日、docker composeでDifyを起動するというメモを書きました。Difyへユーザを招待するにはメールアドレスを登録するのですが、デフォルトの状態では「メールアドレスを登録はするものの、実際にメールは送信されない」という動作をします。SMTPの設定を行うことでメールを送信するよう、設定を修正します。

検証環境

対象 バージョン
Ubuntu 24.04.3 LTS
Dify 1.8.0

メール送信用のSMTP設定を行う

docker composeで起動する際の設定ファイルはdify/docker/.envです。これを以下のように修正します。メールの送信にはAWS SESを利用します。デフォルトではResendが指定されています。

変更前

18
19
# Example: https://console.dify.ai
CONSOLE_WEB_URL=
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
# Mail type, support: resend, smtp, sendgrid
MAIL_TYPE=resend

# Default send from email address, if not specified
# If using SendGrid, use the 'from' field for authentication if necessary.
MAIL_DEFAULT_SEND_FROM=

# API-Key for the Resend email provider, used when MAIL_TYPE is `resend`.
RESEND_API_URL=https://api.resend.com
RESEND_API_KEY=your-resend-api-key


# SMTP server configuration, used when MAIL_TYPE is `smtp`
SMTP_SERVER=
SMTP_PORT=465
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_USE_TLS=true
SMTP_OPPORTUNISTIC_TLS=false

変更後

CONSOLE_WEB_URLの指定が無くても招待メールは届くのですが、アクティベーション用のボタンが正しく動作しません。

18
19
# Example: https://console.dify.ai
CONSOLE_WEB_URL=http://example.com
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
# Mail type, support: resend, smtp, sendgrid
MAIL_TYPE=smtp

# Default send from email address, if not specified
# If using SendGrid, use the 'from' field for authentication if necessary.
MAIL_DEFAULT_SEND_FROM=no-reply@example.com

# API-Key for the Resend email provider, used when MAIL_TYPE is `resend`.
RESEND_API_URL=https://api.resend.com
RESEND_API_KEY=your-resend-api-key


# SMTP server configuration, used when MAIL_TYPE is `smtp`
SMTP_SERVER=email-smtp.us-east-1.amazonaws.com
SMTP_PORT=587
SMTP_USERNAME=12345678901234567890
SMTP_PASSWORD=12345678901234567890123456789012345678901234
SMTP_USE_TLS=true
SMTP_OPPORTUNISTIC_TLS=true

Difyを起動する

設定修正が完了したらdocker composeでDifyを起動します。下記の例ではベクトルデータベースにQdrantを指定していますが、これは必須ではありません。

docker compose --profile qdrant up -d

メンバーへ招待メールを送信する

設定メンバーからメールアドレスを入力するとアクティベーションリンク付きのメールが送信されます。

image