feat: Add SMTP mail sending feature via msmtp
All checks were successful
Helm Chart Release / release-chart (push) Successful in 5s

PHPアプリケーションからSMTP経由でメール送信を行う機能を追加。
msmtpをPHP-FPMコンテナに統合し、mail()関数で直接利用可能。

Features:
- STARTTLS(port 587)とSSL/TLS(port 465)に対応
- 送信元アドレスは固定だがPHPで上書き指定可能
- パスワードはKubernetes Secretで安全に管理
- 自己署名証明書対応オプション
- Gmail、Office365など一般的なSMTPサーバーに対応

Changes:
- values.yaml: smtp設定セクションを追加
- templates/secret-smtp.yaml: パスワード管理用Secret
- templates/configmap-smtp.yaml: msmtprc設定ファイル生成
- templates/configmap-smtp.yaml: PHPヘルパークラス(SmtpConfig)
- templates/deployment.yaml: msmtpインストールと設定
- README.md: SMTP設定パラメータ表と使用例を追加

Protocol support:
- auto: 自動判定(推奨)
- starttls: SMTP + STARTTLS(ポート587)
- tls: SSL/TLS(ポート465)

PHP Usage:
  SmtpConfig::init();
  mail($to, $subject, $body);
  // または別の送信者で上書き
  SmtpConfig::mail($to, $subject, $body, $headers, 'custom@example.com');

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 10:40:07 +09:00
parent 8b7a141caa
commit 06c63037f1
5 changed files with 385 additions and 2 deletions

View File

@@ -51,7 +51,12 @@ spec:
# MySQL/MariaDB接続に必要なパッケージ
APK_PACKAGES="$APK_PACKAGES mysql-client mysql-dev"
{{- end }}
{{- if .Values.smtp.enabled }}
# SMTP送信に必要なパッケージ
APK_PACKAGES="$APK_PACKAGES msmtp ca-certificates"
{{- end }}
{{- if .Values.composer.additionalApkPackages }}
# ユーザー指定の追加APKパッケージ
{{- range .Values.composer.additionalApkPackages }}
@@ -142,7 +147,30 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.smtp.enabled }}
# ========================================
# SMTP設定msmtp
# ========================================
echo "Configuring SMTP for mail sending..."
# msmtprc設定ファイルをコピー
cp /etc/smtp-config/msmtprc /etc/msmtprc
chmod 600 /etc/msmtprc
# PHP設定をphp.ini.d/に作成
cat > /usr/local/etc/php/conf.d/99-smtp.ini << 'PHP_SMTP_EOF'
; SMTP設定 - msmtp経由でメール送信
sendmail_path = "/usr/bin/msmtp -t"
sendmail_from = "{{ .Values.smtp.from }}"
PHP_SMTP_EOF
echo "SMTP configured:"
echo " Host: {{ .Values.smtp.host }}:{{ .Values.smtp.port }}"
echo " Protocol: {{ .Values.smtp.protocol }}"
echo " From: {{ .Values.smtp.from }}"
{{- end }}
echo "Setup complete, starting PHP-FPM..."
php-fpm
ports:
@@ -155,6 +183,16 @@ spec:
- name: composer-config
mountPath: /tmp/composer-init
{{- end }}
{{- if .Values.smtp.enabled }}
- name: smtp-config
mountPath: /etc/smtp-config
readOnly: true
{{- if .Values.smtp.auth.enabled }}
- name: smtp-secrets
mountPath: /etc/smtp-secrets
readOnly: true
{{- end }}
{{- end }}
env:
{{- if .Values.externalDatabase.enabled }}
- name: DB_HOST
@@ -202,4 +240,21 @@ spec:
- name: composer-config
configMap:
name: {{ include "phpfpm.fullname" . }}-composer-config
{{- end }}
{{- if .Values.smtp.enabled }}
- name: smtp-config
configMap:
name: {{ include "phpfpm.fullname" . }}-smtp-config
items:
- key: msmtprc
path: msmtprc
{{- if .Values.smtp.auth.enabled }}
- name: smtp-secrets
secret:
secretName: {{ include "phpfpm.fullname" . }}-smtp
items:
- key: password
path: password
mode: 0600
{{- end }}
{{- end }}