Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29748

Laravel send email via SMTP fails on Azure, local environment works fine

$
0
0

I'm developing a Laravel application and I need to use different settings to send emails (so users can send a message with their own email). I've set that up and it is working fine right now-- however, only in localhost test environments. When I move to production server (Azure VM), I always get the same error:

Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required

Regardless of whatever port and encryption type I'm using.

This is what I'm doing in my custom 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');
  }
}

This approach works on local environments (scenario 1: Xampp on Windows, scenario 2: homestead) but not on the Azure VM, which is production environment. I've tested the same 3 email settings, they all throw the same error in production and send emails correctly in test environment.

Any help will be greatly appreciated.


Viewing all articles
Browse latest Browse all 29748

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>