kinglozzer / silverstripe-mailgunner

Mailgun integration for SilverStripe emails
BSD 3-Clause "New" or "Revised" License
7 stars 7 forks source link

Update use of deprecated Mailgun APIs #9

Open kinglozzer opened 7 years ago

kinglozzer commented 7 years ago

BatchMessage() and MessageBuilder() currently still use legacy APIs of their own internally, so they will have to wait to be updated...

ARNHOE commented 7 years ago

Any idea when this will be available?

kinglozzer commented 7 years ago

@ARNHOE When what will be available? Version 3.0.0 of this module uses mailgun-php: 2.x, the deprecated APIs don’t need to be updated for it to work 😃

ARNHOE commented 7 years ago

@kinglozzer Couldnt get dev-master work, but 2.x works perfectly. Found out after the comment

rmsj commented 7 years ago

Does this work for local development? This is the error message I get:

Debug (line 140 of Mailer.php): Mailgun error: An HTTP Error has occurred! Check your network connection and try again.

kinglozzer commented 7 years ago

It does work locally, can you check which version of this module you’re using and paste your mailgun config?

rmsj commented 7 years ago

Version installed is the latest I think. The configuration is as per this

Mailgun


After: 'silverstripe-mailgun'

Kinglozzer\SilverStripeMailgunner\Mailer: api_domain: 'some_long_sand_boxurl.mailgun.org' api_key: 'key-my-api-key'

After: 'silverstripe-mailgun' Only: environment: 'dev'

Get your own Postbin ID by visiting http://bin.mailgun.net

Kinglozzer\SilverStripeMailgunner\Mailer: api_endpoint: 'http://bin.mailgun.net/C6f04a3a' debug: true

kinglozzer commented 7 years ago

composer show will show you which version you have installed. That all looks correct, it’s very similar to the configuration I used for when working on the module. I simply skipped the environment conditions:

---
Name: mailgun
After: 'silverstripe-mailgun'
---
Kinglozzer\SilverStripeMailgunner\Mailer:
  api_domain: 'https://api.mailgun.net/v3/sandbox123456789987654321.mailgun.org'
  api_endpoint: 'http://bin.mailgun.net/12345abcde'
  api_key: 'key-1234564789876543212345678987654321'
  debug: true
rmsj commented 7 years ago

kinglozzer/silverstripe-mailgunner 3.1.0 as per composer show.

rmsj commented 7 years ago

Using mail gun directly works just fine (example below), using the class doesn't.

# Instantiate the client.
        $mgClient = new Mailgun('my_key');
        $domain = "sandbox123456789987654321.mailgun.org";

        # Make the call to the client.
        $result = $mgClient->sendMessage("$domain",
            array('from'    => 'Mailgun Sandbox <postmaster@ sandbox123456789987654321.mailgun.org>',
                'to'      => 'Ronaldo <myemail@hotmail.com>',
                'subject' => 'Hello Ronaldo',
                'html'    => '<h1>Congratulations Ronaldo Santana</h1><p>You just sent an email with Mailgun!  You are truly awesome!</p> '));
kinglozzer commented 7 years ago

I just tried again using the same config and my own credentials and couldn’t recreate this. Could you add the following to the catch (Exception $e) block here and see what the error is in more detail?

if ($e instanceof \Mailgun\Connection\Exceptions\GenericHTTPError) {
    var_dump($e->getHttpResponseBody());
    die;
}

The postbins do expire after a while, so it may be worth checking that too.