预期响应代码 250 但收到代码“554”,消息“554 消息被拒绝 | Laravel 使用 TO 电子邮件
Expected response code 250 but got code "554", with message "554 Message rejected | Laravel Using TO Email
- Laravel版本:8.27
- PHP 版本
$ php --version
: PHP 8.0.3 (cli)
- 数据库驱动程序和版本 $
mysql --version
: mysql Ver 8.0.23-0ubuntu0.20.04.1
问题陈述:
我在 FROM
电子邮件中收到 TO
电子邮件,当然不会在其中验证POST
password/email
.
中的亚马逊 SES
描述:
让 to@example2.com 将通过电子邮件要求重设密码 Link。一般from@example1.com会发送密码重置link。但是,在我的例子中,to@example2.com 试图将密码重置 link 发送给自己。
在Amazon SES 中我们需要验证电子邮件才能通过SES 服务发送邮件。所以我验证了 from@example1.com.
Note: Both domain are different example1.com
and example2.com
. example1.com
is setup on Amazon SES.
异常:
Swift_TransportException (554)
Expected response code 250 but got code "554", with message "554 Message rejected: Email address is not verified. The following identities failed the check in region REGION: to@example2.com "
配置:
$ php artisan route:list
+--------+----------+-----------------------------------------------+------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------------------------------+------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------+
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web |
App\Http\Controllers\Auth\ForgotPasswordController.php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
use SendsPasswordResetEmails;
vendor\laravel\ui\auth-backend\SendsPasswordResetEmails.php
namespace Illuminate\Foundation\Auth;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;
use Illuminate\Validation\ValidationException;
trait SendsPasswordResetEmails
{
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
$response = $this->broker()->sendResetLink(
$this->credentials($request)
);
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($request, $response)
: $this->sendResetLinkFailedResponse($request, $response);
}
vendor\laravel\framework\src\illuminate\Auth\Passwords\PasswordBroker.php
namespace Illuminate\Auth\Passwords;
use Closure;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Contracts\Auth\PasswordBroker as PasswordBrokerContract;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Support\Arr;
use UnexpectedValueException;
class PasswordBroker implements PasswordBrokerContract
{
public function sendResetLink(array $credentials, Closure $callback = null)
{
$user = $this->getUser($credentials);
if (is_null($user)) {
return static::INVALID_USER;
}
if ($this->tokens->recentlyCreatedToken($user)) {
return static::RESET_THROTTLED;
}
$token = $this->tokens->create($user);
if ($callback) {
$callback($user, $token);
} else {
$user->sendPasswordResetNotification($token);
}
return static::RESET_LINK_SENT;
.env
MAIL_DRIVER="smtp"
MAIL_HOST="test-smtp.region.amazonaws.com"
MAIL_PORT="25"
MAIL_USERNAME="USER..."
MAIL_PASSWORD="PASS..."
MAIL_ENCRYPTION="tls"
MAIL_FROM_ADDRESS="from@example2.com"
MAIL_FROM_NAME="foo"
在我看来,您的 AWS 邮件服务或 Laravel 设置不正确
https://aws.amazon.com/premiumsupport/knowledge-center/ses-554-400-message-rejected-error/
您可以尝试使用开箱即用的 mailtrap.io 来测试内容。
当应该发送电子邮件的服务器拒绝它时,通常会引发这种异常。通常是 SMTP 或 AWS SES。也有可能是您尝试通过 SMTP 通过 outlook 帐户发送邮件,而安全策略不允许您发送邮件。
但是,如果我没猜错,您希望发送电子邮件就像人们自己发送电子邮件一样。这是不可能的,因为您无法验证所有电子邮件。 *@*
作为解决方案,您可以使用 reply-to
选项,或者如果您不希望用户能够回复,则 no-reply
作为发件人。
如果您不尝试以 to@
发送邮件,而是 from@
确保 MAIL_FROM_EMAIL 在 env.
中正确设置
不应以未加密的方式发送电子邮件
要使用的电子邮件端口:
Protocol Security Setting Port Number(s)
SMTP (sending mail) Encrypted - TLS/STARTTLS 465
SMTP (sending mail) Encrypted - SSL 465
SMTP (sending mail) Unencrypted 25* (or 26)
POP3 (receiving mail) Encrypted - TLS 995
POP3 (receiving mail) Encrypted - SSL 995
POP3 (receiving mail) Unencrypted 110
IMAP (receiving mail) Encrypted - TLS 993
IMAP (receiving mail) Encrypted - SSL 993
IMAP (receiving mail) Unencrypted 143
https://billing.precedence.com.au/billing/knowledgebase/70/Mail-Ports-for-POP3-IMAP-and-SMTP.html
- Laravel版本:8.27
- PHP 版本
$ php --version
: PHP 8.0.3 (cli) - 数据库驱动程序和版本 $
mysql --version
: mysql Ver 8.0.23-0ubuntu0.20.04.1
问题陈述:
我在 FROM
电子邮件中收到 TO
电子邮件,当然不会在其中验证POST
password/email
.
描述:
让 to@example2.com 将通过电子邮件要求重设密码 Link。一般from@example1.com会发送密码重置link。但是,在我的例子中,to@example2.com 试图将密码重置 link 发送给自己。
在Amazon SES 中我们需要验证电子邮件才能通过SES 服务发送邮件。所以我验证了 from@example1.com.
Note: Both domain are different
example1.com
andexample2.com
.example1.com
is setup on Amazon SES.
异常:
Swift_TransportException (554)
Expected response code 250 but got code "554", with message "554 Message rejected: Email address is not verified. The following identities failed the check in region REGION: to@example2.com "
配置:
$ php artisan route:list
+--------+----------+-----------------------------------------------+------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------------------------------+------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------+
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web |
App\Http\Controllers\Auth\ForgotPasswordController.php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
use SendsPasswordResetEmails;
vendor\laravel\ui\auth-backend\SendsPasswordResetEmails.php
namespace Illuminate\Foundation\Auth;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;
use Illuminate\Validation\ValidationException;
trait SendsPasswordResetEmails
{
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
$response = $this->broker()->sendResetLink(
$this->credentials($request)
);
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($request, $response)
: $this->sendResetLinkFailedResponse($request, $response);
}
vendor\laravel\framework\src\illuminate\Auth\Passwords\PasswordBroker.php
namespace Illuminate\Auth\Passwords;
use Closure;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Contracts\Auth\PasswordBroker as PasswordBrokerContract;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Support\Arr;
use UnexpectedValueException;
class PasswordBroker implements PasswordBrokerContract
{
public function sendResetLink(array $credentials, Closure $callback = null)
{
$user = $this->getUser($credentials);
if (is_null($user)) {
return static::INVALID_USER;
}
if ($this->tokens->recentlyCreatedToken($user)) {
return static::RESET_THROTTLED;
}
$token = $this->tokens->create($user);
if ($callback) {
$callback($user, $token);
} else {
$user->sendPasswordResetNotification($token);
}
return static::RESET_LINK_SENT;
.env
MAIL_DRIVER="smtp"
MAIL_HOST="test-smtp.region.amazonaws.com"
MAIL_PORT="25"
MAIL_USERNAME="USER..."
MAIL_PASSWORD="PASS..."
MAIL_ENCRYPTION="tls"
MAIL_FROM_ADDRESS="from@example2.com"
MAIL_FROM_NAME="foo"
在我看来,您的 AWS 邮件服务或 Laravel 设置不正确
https://aws.amazon.com/premiumsupport/knowledge-center/ses-554-400-message-rejected-error/
您可以尝试使用开箱即用的 mailtrap.io 来测试内容。
当应该发送电子邮件的服务器拒绝它时,通常会引发这种异常。通常是 SMTP 或 AWS SES。也有可能是您尝试通过 SMTP 通过 outlook 帐户发送邮件,而安全策略不允许您发送邮件。
但是,如果我没猜错,您希望发送电子邮件就像人们自己发送电子邮件一样。这是不可能的,因为您无法验证所有电子邮件。 *@*
作为解决方案,您可以使用 reply-to
选项,或者如果您不希望用户能够回复,则 no-reply
作为发件人。
如果您不尝试以 to@
发送邮件,而是 from@
确保 MAIL_FROM_EMAIL 在 env.
不应以未加密的方式发送电子邮件
要使用的电子邮件端口:
Protocol Security Setting Port Number(s)
SMTP (sending mail) Encrypted - TLS/STARTTLS 465
SMTP (sending mail) Encrypted - SSL 465
SMTP (sending mail) Unencrypted 25* (or 26)
POP3 (receiving mail) Encrypted - TLS 995
POP3 (receiving mail) Encrypted - SSL 995
POP3 (receiving mail) Unencrypted 110
IMAP (receiving mail) Encrypted - TLS 993
IMAP (receiving mail) Encrypted - SSL 993
IMAP (receiving mail) Unencrypted 143
https://billing.precedence.com.au/billing/knowledgebase/70/Mail-Ports-for-POP3-IMAP-and-SMTP.html