我正在开发Laravel应用程序,我需要使用不同的设置来发送电子邮件(以便用户可以使用自己的电子邮件发送消息)。我已经设置好了,它现在可以正常工作-但是,仅在localhost测试环境中。当我移至生产服务器(Azure VM)时,总是会收到相同的错误:
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
无论我使用什么端口和加密类型。
这是我在自定义Mailable中所做的:
<?php
namespace App\Mail;
use Illuminate\Http\Request;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Repositories\Email;
class DemoEmail extends Mailable
{
use Queueable, SerializesModels;
public $email;
public $request;
public function __construct()
{
}
public function build(Email $email,Request $request)
{
$this->email = $email;
$this->request= $request;
$usrsettings = $this->email->settings();
$conf = [
'driver' => 'smtp',
'host' => $usrsettings["Servidor"],
'port' => $usrsettings["Puerto"],
'from' => [
'address' => $usrsettings["Direccion"],
'name' => $usrsettings["Nombre"],
],
'encryption' => $usrsettings["encrypt"],
'username' => $usrsettings["Cuenta"],
'password' => $usrsettings["Contraseña"],
];
\Config::set('mail',$conf);
if (isset($request['cc']) && $request['cc']!=null) $this->cc($request['cc']);
if (isset($request['bcc']) && $request['bcc']!=null) $this->bcc($request['bcc']);
return $this->from($conf["from"]["address"],$conf["from"]["name"])
->subject($request["subject"])
->view('emails.crm');
}
}
此方法适用于本地环境(方案1:Windows上的Xampp,方案2:家园),但不适用于生产环境Azure VM。我已经测试了相同的3个电子邮件设置,它们在生产中都会引发相同的错误,并在测试环境中正确发送电子邮件。
任何帮助将不胜感激。
我想这是由于您的生产服务器IP被列入黑名单或需要进行身份验证才能发送邮件引起的。
我刚刚在新服务器上遇到了类似的问题-为了发送仅具有SPF记录但没有适当身份验证的IP,需要建立IP并赢得声誉。
我希望在我的网站上发送带有身份验证的邮件几个月后,我应该能够每次发送而无需设置SMTP服务器,用户名和密码。
关于安全性和这些服务的潜在滥用端口,在VM实例上被阻止。您需要手动取消阻止它们。
[一种更好的方法是使用外部服务来处理诸如SendGrid或MailGun之类的电子邮件,但这不是强制性的。