質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

SMTP

SMTP(Simple Mail Transfer Protocol)はIPネットワークでemailを伝送する為のプロトコルです。

Postfix

Postfixは、電子メールサーバソフトウェアで、 メールを配送するシステムMTAの一種です。

Q&A

解決済

1回答

3663閲覧

laravelでpostfixのsmtpサーバーからメールを送信したい。

tomoto

総合スコア11

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

SMTP

SMTP(Simple Mail Transfer Protocol)はIPネットワークでemailを伝送する為のプロトコルです。

Postfix

Postfixは、電子メールサーバソフトウェアで、 メールを配送するシステムMTAの一種です。

0グッド

0クリップ

投稿2022/12/15 14:53

前提

さくらVPS(centos7)でpostfixを使ってメールサーバーを構築済み
ec2でlaravelを使ってAPIサーバーを構築済み

参考サイトを元にメールサーバーを構築し、実際にThunderbirdやiPhoneのメールアカウント設定からアドレスを登録し送受信に成功しました。

仮のドメインとして以下はexample.comをあてていますが実際は独自ドメインです。

実現したいこと

laravelからsmtpでメールを送信したい。

発生している問題・エラーメッセージ

laravelでも同じような設定値でenvファイルに設定しましたが下記のメッセージが出てきました。

postfix/smtpd[1600]: warning: unknown[xxxxxxx]: SASL LOGIN authentication failed: authentication failure

該当のソースコード

postfix

1# postconf -n 2 3alias_database = hash:/etc/aliases 4alias_maps = hash:/etc/aliases 5command_directory = /usr/sbin 6config_directory = /etc/postfix 7daemon_directory = /usr/libexec/postfix 8data_directory = /var/lib/postfix 9debug_peer_level = 2 10debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5 11home_mailbox = Maildir/ 12html_directory = no 13inet_interfaces = all 14inet_protocols = all 15local_recipient_maps = 16luser_relay = unknown_user@localhost 17mail_owner = postfix 18mailq_path = /usr/bin/mailq.postfix 19manpage_directory = /usr/share/man 20message_size_limit = 10485760 21milter_default_action = accept 22mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain 23mydomain = example.com 24myhostname = mail.example.com 25mynetworks_style = host 26myorigin = $mydomain 27newaliases_path = /usr/bin/newaliases.postfix 28non_smtpd_milters = inet:localhost:8891 29queue_directory = /var/spool/postfix 30readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES 31sample_directory = /usr/share/doc/postfix-2.10.1/samples 32sendmail_path = /usr/sbin/sendmail.postfix 33setgid_group = postdrop 34smtp_tls_ciphers = high 35smtp_tls_mandatory_protocols = !SSLv2,!SSLv3 36smtp_tls_protocols = !SSLv2,!SSLv3 37smtp_tls_security_level = may 38smtpd_banner = $myhostname ESMTP unknown 39smtpd_milters = inet:127.0.0.1:8891 40smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination 41smtpd_sasl_auth_enable = yes 42smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem 43smtpd_tls_ciphers = high 44smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem 45smtpd_tls_mandatory_ciphers = high 46smtpd_tls_mandatory_protocols = !SSLv2,!SSLv3 47smtpd_tls_protocols = !SSLv2,!SSLv3 48smtpd_tls_security_level = may 49smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_scache 50tls_high_cipherlist = kEECDH:+kEECDH+SHA:kEDH:+kEDH+SHA:+kEDH+CAMELLIA:kECDH:+kECDH+SHA:kRSA:+kRSA+SHA:+kRSA+CAMELLIA:!aNULL:!eNULL:!SSLv2:!RC4:!MD5:!DES:!EXP:!SEED:!IDEA:!3DES 51unknown_local_recipient_reject_code = 550

etc/dovecot/conf.d/10ssl.conf

1ssl = yes

etc/dovecot/conf.d/10auth.conf

1disable_plaintext_auth = no

env

1MAIL_MAILER=smtp 2MAIL_HOST=mail.example.com 3MAIL_PORT=465 4MAIL_USERNAME=info@example.com 5MAIL_PASSWORD=xxxxxxxxxxxxxxxxxx 6MAIL_ENCRYPTION=tls 7MAIL_FROM_ADDRESS=info@example.com 8MAIL_FROM_NAME="${APP_NAME}"

試したこと、 参考サイト

https://centossrv.com/postfix.shtml
https://qiita.com/Sabuuuuu---nn/items/fc5448b7f5e3057365a1

基本的にはこの2サイトを参考にメールサーバーを構築しました。

https://centossrv.com/postfix.shtml において、
途中分岐があり後者の「SMTP認証に個別のユーザー名、パスワードを使用する場合」を採用してます。

SMTP認証にシステムのユーザー名、パスワードを使用する場合 [root@centos ~]# yum -y install cyrus-sasl ← cyrus-saslインストール [root@centos ~]# systemctl start saslauthd ← saslauthd起動 [root@centos ~]# systemctl enable saslauthd ← saslauthd自動起動設定 SMTP認証に個別のユーザー名、パスワードを使用する場合 [root@centos ~]# vi /etc/sasl2/smtpd.conf ← SMTP認証設定ファイル編集 pwcheck_method: saslauthd ↓ pwcheck_method: auxprop ← 変更

env

1MAIL_MAILER→ smtp, sendmail 2MAIL_PORT→ 25, 465, 587 3MAIL_USERNAME→ info, info@example.com 4MAIL_ENCRYPTION→ tls, ssl, null

envファイルはそれぞれ色んな組み合わせで送信処理しましたが/var/log/maillogに表示されなかったり同じエラーメッセージだったりで、いまいちメールサーバーとlaravelのどっちが悪いのかわからないです。

laravelのsmtp送信に関してはawsのworkmail,gmail,エックスサーバーを使い過去に何度かやった事があります。

補足情報(FW/ツールのバージョンなど)

centos7

postfix

1# postconf | grep mail_version 2mail_version = 2.10.1

https://centossrv.com/postfix-dovecot-certbot.shtml よりユーザーを作成しましたが片方はいらないです。

user

1# sasldblistusers2 2info@example.com: userPassword 3info@mail.example.com: userPassword

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

CHERRY

2022/12/15 21:48

smtpの認証エラーが発生していますね。 smtp 送信時の認証に使用しているユーザー、パスワードは、saslauthd で認証に成功するユーザーとパスワードでしょうか。
tomoto

2022/12/16 02:07

laravel側のメール送信に不備があっただけのようでした。
guest

回答1

0

自己解決

laravel側のメール送信に不備があっただけのようでした。

投稿2022/12/16 02:07

tomoto

総合スコア11

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問