Code Monkey home page Code Monkey logo

azure-mailer-driver's People

Contributors

hafael avatar tobiashammarstrand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

azure-mailer-driver's Issues

Poll for email send status result

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.

https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/email/send-email-advanced/manually-poll-for-email-status?tabs=connection-string#sending-email-async-and-polling-for-the-email-send-status

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?

AbstractTransportFactory dependencies are not passed to AzureMailerApiTransport

AzureMailerTransportFactory extends AbstractTransportFactory

final class 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

return new AzureMailerApiTransport($endpoint, $key, $apiVersion, $engagementTracking);

despite accepting them:

public function __construct(string $endpoint, string $key, string $apiVersion = null, bool $engagementTracking = true, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)

Add help for projects that requires "minimum-stability": "stable"

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.

"symfony/azure-mailer": "^7.0"

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.

Emails Not Sending - 202 Status

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.

  1. I have a custom email domain I am sending through. It is fully verified / DKIM / SPF. It is also provisioned to the Communication Service instance I am trying to use. I think this is all set up correctly.
  2. I did have some issues with selecting the right API version in the .env. I am now running on 2023-03-31. (Just a note your docs default the .env config to the 2021 version which had a ton of different errors.
  3. Package version is .0.2.0
  4. I have verified my senderAddress matches what I have configured in azure for the domain as well.

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.

HttpClient is null in AzureMailerManager

Environment:

  • PHP 8.2
  • hafael/azure-mailer-driver v0.2.2

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.

HttpClientInterface is marked as optional, but will fail if not provided

In

public function __construct(string $endpoint, string $key, string $apiVersion = null, bool $engagementTracking = true, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)

the HttpClientInterface is marked as optional, but if it is not provided, this line will fail:
$response = $this->client->request('POST', $endpointURL, $requestOptions);

README states a requirement that is not in composer.json

The README.md states that symfony/http-client is a requirement:

- [symfony/http-client](https://github.com/symfony/http-client)

Indeed, if the interface is missing, this line will fail

$response = $this->client->request('POST', $endpointURL, $requestOptions);

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

"require": {
"php": ">=8.1",
"symfony/mailer": "^5.4.21|^6.2.7"
},

even something as broad as *, while not being accurate, is better than nothing.

Error SSL Symfony: SSL operation failed with code 1. OpenSSL Error messages:\nerror:1416F086:SS

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.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.