Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 10 #181

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@
"license": "MIT",
"authors": [],
"require": {
"php": "^7.3 || ^8.0",
"ext-json": "*",
"aws/aws-sdk-php-laravel": "^3.6",
"doctrine/dbal": "^3.0",
"illuminate/support": "^8.0",
"aws/aws-sdk-php-laravel": "^3.8",
"illuminate/support": "^10.0",
"kriswallsmith/buzz": "^1.2",
"mailgun/mailgun-php": "^3.2",
"mailgun/mailgun-php": "^3.5",
"mailjet/mailjet-apiv3-php": "^1.5",
"nyholm/psr7": "^1.3",
"rap2hpoutre/fast-excel": "^2.3",
"rap2hpoutre/fast-excel": "^5.1",
"sendgrid/sendgrid": "^7.9",
"wildbit/postmark-php": "^4.0",
"postal/postal": "^1.0"
},
"require-dev": {
"orchestra/testbench": "^6.0",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^9.0",
"roave/security-advisories": "dev-master"
},
Expand All @@ -43,7 +41,10 @@

},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
},
"extra": {
"laravel": {
Expand Down
4 changes: 2 additions & 2 deletions resources/views/subscribers/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class="btn btn-md btn-light">{{ __('Clear') }}</a>

@slot('right')
<div class="btn-group mr-2">
<button class="btn btn-md btn-default dropdown-toggle" type="button" data-toggle="dropdown">
<i class="fa fa-bars color-gray-400"></i>
<button class="btn btn-md btn-light dropdown-toggle" type="button" data-toggle="dropdown">
{{ __('Bulk actions') }}
</button>
<div class="dropdown-menu">
<a href="{{ route('sendportal.subscribers.import') }}" class="dropdown-item">
Expand Down
62 changes: 37 additions & 25 deletions src/Adapters/SmtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,80 @@

use Illuminate\Support\Arr;
use Sendportal\Base\Services\Messages\MessageTrackingOptions;
use Swift_Mailer;
use Swift_Message;
use Swift_SmtpTransport;
use Swift_TransportException;

use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mailer\Exception\TransportException;

class SmtpAdapter extends BaseMailAdapter
{
/** @var Swift_Mailer */
/** @var Mailer */
protected $client;

/** @var Swift_SmtpTransport */
/** @var ESmtpTransport */
protected $transport;

public function send(string $fromEmail, string $fromName, string $toEmail, string $subject, MessageTrackingOptions $trackingOptions, string $content): string
{
$failedRecipients = [];

// $failedRecipients = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyone else that can help out on this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it's not possible to get failed recipients. see symfony/symfony#33812

try {
$result = $this->resolveClient()->send($this->resolveMessage($subject, $content, $fromEmail, $fromName, $toEmail), $failedRecipients);
} catch (Swift_TransportException $e) {
$result = $this->resolveClient()->send($this->resolveMessage($subject, $content, $fromEmail, $fromName, $toEmail));
} catch (TransportException $e) {
return $this->resolveMessageId(0);
}

return $this->resolveMessageId($result);
}

protected function resolveClient(): Swift_Mailer
protected function resolveClient(): Mailer
{
if ($this->client) {
return $this->client;
}

$this->client = new Swift_Mailer($this->resolveTransport());
$this->client = new Mailer($this->resolveTransport());

return $this->client;
}

protected function resolveTransport(): Swift_SmtpTransport
protected function resolveTransport(): EsmtpTransport
{
if ($this->transport) {
return $this->transport;
}

$this->transport = new Swift_SmtpTransport(
$factory = new EsmtpTransportFactory();

$encryption = Arr::get($this->config, 'encryption');

$scheme = !is_null($encryption) && $encryption === 'tls'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda feel like this should just be exposed in the config instead of some behind the scenes magic. Thoughts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encryption isn't an explicit config in symfony, so the examples I saw where checking for tls and the port to determine the schema, then mailer is configured only by a dsn string...

? ((Arr::get($this->config, 'port') == 465) ? 'smtps' : 'smtp')
: '';

$dsn = new Dsn(
$scheme,
Arr::get($this->config, 'host'),
Arr::get($this->config, 'port'),
Arr::get($this->config, 'encryption')
Arr::get($this->config, 'username'),
Arr::get($this->config, 'password'),
Arr::get($this->config, 'port')
);

$this->transport->setUsername(Arr::get($this->config, 'username'));
$this->transport->setPassword(Arr::get($this->config, 'password'));
$this->transport->setAuthMode('login');
$this->transport = $factory->create($dsn);

return $this->transport;
}

protected function resolveMessage(string $subject, string $content, string $fromEmail, string $fromName, string $toEmail): Swift_Message
protected function resolveMessage(string $subject, string $content, string $fromEmail, string $fromName, string $toEmail): Email
{
$msg = new Swift_Message($subject, $content, 'text/html');

$msg->setTo($toEmail);
$msg->setFrom($fromEmail, $fromName);
$msg = (new Email())
->from(new Address($fromEmail, $fromName))
->to($toEmail)
->subject($subject)
->html($content);

return $msg;
}
Expand Down