Helm Chart Release / release-chart (push) Successful in 6s
helmchart/secret-manager が各ネームスペースへ配布する cred-* Secret を phpfpm 側から参照できるようにする。 - extraEnvFrom / extraEnv: 既存 Secret/ConfigMap を php-fpm コンテナへ env 注入 - smtp.auth.existingSecret / existingSecretKey: パスワードファイルだけ既存 Secret から取得 - smtp.existingMsmtprcSecret / existingMsmtprcSecretKey: 完成済み msmtprc を そのままマウント(指定時は configmap-smtp を生成せず host/port/auth.* は無視) 既定値は全て空のため既存挙動は不変。手動リリース 8.5.10-a。
158 lines
4.7 KiB
YAML
158 lines
4.7 KiB
YAML
{{- if and .Values.smtp.enabled (not .Values.smtp.existingMsmtprcSecret) }}
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: {{ include "phpfpm.fullname" . }}-smtp-config
|
|
labels:
|
|
{{- include "phpfpm.labels" . | nindent 4 }}
|
|
data:
|
|
msmtprc: |
|
|
# msmtp設定ファイル
|
|
# PHPのsendmail_pathから呼び出される
|
|
|
|
defaults
|
|
{{- if .Values.smtp.tls.verify }}
|
|
tls on
|
|
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
|
{{- else }}
|
|
tls off
|
|
{{- end }}
|
|
{{- if .Values.smtp.tls.allowSelfSigned }}
|
|
tls_certcheck off
|
|
{{- else }}
|
|
tls_certcheck on
|
|
{{- end }}
|
|
{{- if eq .Values.smtp.protocol "starttls" }}
|
|
# STARTTLS (SMTP + STARTTLS at port 587)
|
|
protocol smtp
|
|
{{- else if eq .Values.smtp.protocol "tls" }}
|
|
# SSL/TLS (SMTPS at port 465)
|
|
protocol smtps
|
|
{{- else }}
|
|
# Auto mode - protocol will be determined by port
|
|
{{- if eq (int .Values.smtp.port) 465 }}
|
|
protocol smtps
|
|
{{- else }}
|
|
protocol smtp
|
|
{{- end }}
|
|
{{- end }}
|
|
|
|
account default
|
|
host {{ .Values.smtp.host }}
|
|
port {{ .Values.smtp.port }}
|
|
{{- if eq .Values.smtp.protocol "starttls" }}
|
|
protocol smtp
|
|
{{- else if eq .Values.smtp.protocol "tls" }}
|
|
protocol smtps
|
|
{{- else if eq (int .Values.smtp.port) 465 }}
|
|
protocol smtps
|
|
{{- else }}
|
|
protocol smtp
|
|
{{- end }}
|
|
|
|
{{- if .Values.smtp.auth.enabled }}
|
|
auth on
|
|
user {{ .Values.smtp.auth.username }}
|
|
passwordeval "cat /etc/smtp-secrets/password"
|
|
{{- else }}
|
|
auth off
|
|
{{- end }}
|
|
|
|
from {{ .Values.smtp.from }}
|
|
{{- if .Values.smtp.tls.verify }}
|
|
tls on
|
|
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
|
{{- else }}
|
|
tls off
|
|
{{- end }}
|
|
{{- if .Values.smtp.tls.allowSelfSigned }}
|
|
tls_certcheck off
|
|
{{- else }}
|
|
tls_certcheck on
|
|
{{- end }}
|
|
|
|
# PHPスクリプトで利用する設定用PHPクラス
|
|
php-smtp-config.php: |
|
|
<?php
|
|
/**
|
|
* PHPからSMTP設定を利用するためのヘルパークラス
|
|
* 使用例:
|
|
* SmtpConfig::init();
|
|
* mail($to, $subject, $body);
|
|
*
|
|
* // 別の送信者で上書きする場合:
|
|
* $headers = [
|
|
* 'From: custom@example.com',
|
|
* 'Return-Path: custom@example.com',
|
|
* ];
|
|
* mail($to, $subject, $body, implode("\r\n", $headers), '-f custom@example.com');
|
|
*/
|
|
class SmtpConfig {
|
|
private static $initialized = false;
|
|
|
|
/**
|
|
* SMTP設定を初期化
|
|
* PHP-FPMスタートアップ時に呼び出す
|
|
*/
|
|
public static function init() {
|
|
if (self::$initialized) {
|
|
return;
|
|
}
|
|
|
|
// PHPメール設定の確認
|
|
$sendmailPath = ini_get('sendmail_path');
|
|
if (!empty($sendmailPath)) {
|
|
error_log("SMTP configured via sendmail_path: " . $sendmailPath);
|
|
}
|
|
|
|
self::$initialized = true;
|
|
}
|
|
|
|
/**
|
|
* 指定した送信者でメール送信
|
|
*
|
|
* @param string $to 受信者アドレス
|
|
* @param string $subject メール件名
|
|
* @param string $body メール本文
|
|
* @param array $headers オプションのヘッダー
|
|
* @param string $fromAddress 送信元アドレス(オプション)
|
|
* @return bool
|
|
*/
|
|
public static function mail($to, $subject, $body, $headers = [], $fromAddress = null) {
|
|
$headerString = '';
|
|
if (!empty($headers)) {
|
|
if (is_array($headers)) {
|
|
$headerString = implode("\r\n", $headers);
|
|
} else {
|
|
$headerString = (string)$headers;
|
|
}
|
|
}
|
|
|
|
// 送信元アドレスでmsmtpを呼び出す
|
|
$parameters = '';
|
|
if (!empty($fromAddress)) {
|
|
// メールヘッダーにFromを追加
|
|
if (!preg_match('/^From:/mi', $headerString)) {
|
|
$headerString .= (!empty($headerString) ? "\r\n" : '') . "From: " . $fromAddress;
|
|
}
|
|
// sendmail互換パラメータで送信者を指定
|
|
$parameters = '-f ' . escapeshellarg($fromAddress);
|
|
}
|
|
|
|
return mail($to, $subject, $body, $headerString, $parameters);
|
|
}
|
|
|
|
/**
|
|
* PHPのメール設定を取得
|
|
*/
|
|
public static function getConfig() {
|
|
return [
|
|
'sendmail_path' => ini_get('sendmail_path'),
|
|
'sendmail_from' => ini_get('sendmail_from'),
|
|
'SMTP' => ini_get('SMTP'),
|
|
'smtp_port' => ini_get('smtp_port'),
|
|
];
|
|
}
|
|
}
|
|
{{- end }}
|