hafael / azure-mailer-driver Goto Github PK
View Code? Open in Web Editor NEWProvides Azure Communication Service integration for Symfony Mailer / Laravel.
License: MIT License
Provides Azure Communication Service integration for Symfony Mailer / Laravel.
License: MIT License
Hello
Okay so this is a bit of a follow up on this previous issue (#2)
I understand how the azure api is working in essentially an async way. POST the message, immediate 202 response. But the email could still fail later.
I saw examples for the C# implementation that ping the status api.
In my debugging of my issue I actually implemented this by setting up that second api request and throwing it at the bottom of the sendApi method:
https://github.com/hafael/azure-mailer-driver/blob/main/src/AzureMailerApiTransport.php#L122
Would there be interest in implementing this as maybe an alternate sending method. It may have to go in as a configuration setting as I don't know how else to pass a call to it down from Laravel's mail::
facade. Basically, it would poll with progressive backoff and throw an exception if it gets a non-success result.
Thoughts?
AzureMailerTransportFactory
extends AbstractTransportFactory
which has dependencies:
https://github.com/symfony/symfony/blob/60e5f25f78f025bb81ec605f7a6fd664667f9e0e/src/Symfony/Component/Mailer/Transport/AbstractTransportFactory.php#L24-L33
but these dependencies are not passed on to AzureMailerApiTransport
despite accepting them:
In a project with minimum-stability: stable (which is the default stability of a new Laravel project)
composer require hafael/azure-mailer-driver
is not enough to install the latest v0.3.0. Composer will fallback to v0.2.2.
The problem is, that the dependend package symfony/azure-mailer has currently no stable version.
azure-mailer-driver/composer.json
Line 11 in e793d56
When I try to explicit install v0.3.0 this happens:
composer require hafael/azure-mailer-driver:v0.3.0
./composer.json has been updated
Running composer update hafael/azure-mailer-driver
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires hafael/azure-mailer-driver v0.3.0 -> satisfiable by hafael/azure-mailer-driver[v0.3.0].
- hafael/azure-mailer-driver v0.3.0 requires symfony/azure-mailer ^7.0 -> found symfony/azure-mailer[7.1.x-dev] but it does not match your minimum-stability.
Solution which can be documented in the README.md
Allow unstable version of symfony/azure-mailer first:
composer require symfony/azure-mailer:@dev
Now its fine to run
composer require hafael/azure-mailer-driver
which install v0.3.0
But I get one more problem at runtime during a mail send:
You cannot use \"Symfony\\Component\\Mailer\\Transport\\AbstractHttpTransport\" as the HttpClient component is not installed. Try running \"composer require symfony/http-client\
So yes, I have to
composer require symfony/http-client
And now it works. I think this could also part of your README.md.
Hello
Excited to try to make use of this in my app. I am running into a few small problems sending emails successfully I'm not sure if I'm doing something wrong or if there's something else going on.
2023-03-31
. (Just a note your docs default the .env config to the 2021 version which had a ton of different errors..0.2.0
I am currently not getting any exceptions thrown when I send an email:
public function handle()
{
$user = User::where('id', '=', 1)->firstOrFail();
try {
Mail::to($user)->send(new \App\Mail\TestEmail());
} catch (\Symfony\Component\Mailer\Exception\HttpTransportException $exception) {
$this->error($exception->getMessage());
// $this->error($exception->getResponse()->getContent());
$this->error(dd($exception->getResponse()->getInfo()));
$this->error($exception->getResponse()->getStatusCode());
// throw $exception;
} catch (\Symfony\Component\HttpClient\Exception\ClientException $exception) {
$this->error($exception->getMessage());
// $this->error($exception->getResponse()->getContent());
$this->error(dd($exception->getResponse()->getInfo()));
$this->error($exception->getResponse()->getStatusCode());
// throw $exception;
}
$this->output->success("Sent!");
}
However I do not receieve the email, and when I review the logs in azure I do see some evidence that the api calls are making it. When I dump the api request response I get:
"{"id":"da7dd26f77b92398ee7867995788dfaa","status":"Running","error":null}"
202
array:9 [
So status running and response code 202 seem right. But again, no email being sent out. When I test with the azure CLI:
az communication email send --sender "[email protected]" --subject "Contoso Update" --to "[email protected]" --text "Hello valued client. There is an update." --connection-string "xxx"
{
"error": null,
"id": "264c8e46-596b-49ed-84ad-63f42dbd2378",
"status": "Succeeded"
}
I get an immediate status succeded. And I do receive the email.
Any ideas on what to check here? I would really love to use this driver but I don't seem to be able to figure out what I'm missing and why its not sending.
Environment:
Error:
"message": "Hafael\\Azure\\Transport\\AzureMailerApiTransport::__construct(): Argument #5 ($client) must be of type Symfony\\Contracts\\HttpClient\\HttpClientInterface, null given, called in ...\\vendor\\hafael\\azure-mailer-driver\\src\\AzureMailerManager.php on line 13",
"exception": "TypeError",
"file": "...\\vendor\\hafael\\azure-mailer-driver\\src\\AzureMailerApiTransport.php",
Please have look at AzureMailerManager
protected function createAzureTransport()
{
$config = $this->app['config']->get('mail.mailers.azure', []);
return new AzureMailerApiTransport(
$config['endpoint'],
$config['access_key'],
$config['api_version'],
boolval($config['disable_user_tracking']),
$this->getHttpClient([]),
);
}
This method calls getHttpClient
with an empty array.
But if you look at MailManager
, with an empty array, the HttpClient will be always null:
/**
protected function getHttpClient(array $config)
{
if ($options = ($config['client'] ?? false)) {
$maxHostConnections = Arr::pull($options, 'max_host_connections', 6);
$maxPendingPushes = Arr::pull($options, 'max_pending_pushes', 50);
return HttpClient::create($options, $maxHostConnections, $maxPendingPushes);
}
}
When I replace it with HttpClient::create([], 3, 3)
I'am able to send an email successfully.
But I don't know, what would be the right options for getHttpClient
. So I will not create a pull request.
In
HttpClientInterface
is marked as optional, but if it is not provided, this line will fail:in laravel 9 I get error:
Class "Illuminate\Mail\Transport\Transport" not found.
Can anyone please guide?
The README.md
states that symfony/http-client is a requirement:
Line 18 in 689f712
Indeed, if the interface is missing, this line will fail
Since this is a non-optional dependency, it would be better to include symfony/http-client in the require
portion of the composer.json
file
azure-mailer-driver/composer.json
Lines 9 to 12 in 689f712
*
, while not being accurate, is better than nothing.Hello, thank you for your package, it has been of great help to me, however I am presenting an error when the email is sent, I was able to resolve the error and finally discovered that it is an SSL error. The solution that has worked for me is adding that the SSL is not verified when you create the AzureMailerApiTransport
It is possible that you can add this in an upcoming update, or better yet let us decide from the Laravel project configuration which options for creating the HTTP client can be used.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.