squareboat / sneaker

An easy way to send emails whenever an exception occurs on server.
MIT License
222 stars 46 forks source link

Allow to specify FROM EMAIL #23

Open tarhe opened 6 years ago

tarhe commented 6 years ago

When using Sneaker with app deployed to ElasticBeanSteak on AWS and using AWS mail features, mails don't get sent because the FROM EMAIL field needs to be an email that is verified or can be verified.

You will get the error below:

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 US-EAST-1: Example hello@example.com, hello@example.com

To solve this, allow the developer to specify From Email in the config file.

I solved mine like so:

File: config/sneaker.php

"sender" => [ "support@example.com", ],

File: vendor/squareboat/sneaker/src/Sneaker.php

` private function capture($exception) { $recipients = $this->config->get('sneaker.to');

    $sender = $this->config->get('sneaker.sender');

    $subject = $this->handler->convertExceptionToString($exception);

    $body = $this->handler->convertExceptionToHtml($exception);

    $this->mailer->to($recipients)->send(new ExceptionMailer($subject, $body, $sender));
}`

And then vendor/squareboat/sneaker/src/ExceptionMailer.php

`class ExceptionMailer extends Mailable implements ShouldQueue { use Queueable, SerializesModels;

/**
 * The subject of the message.
 *
 * @var string
 */
public $subject;

/**
 * The body of the message.
 *
 * @var string
 */
public $body;

/**
 * The sender of the message.
 *
 * @var string
 */
public $sender;

/**
 * Create a new message instance.
 *
 * @return void
 */
public function __construct($subject, $body, $sender)
{
    $this->subject = $subject;

    $this->body = $body;

    $this->sender = $sender;
}

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from($this->sender[0])
                ->view('sneaker::raw')
                ->with('content', $this->body);
}`