Error 500: Mailgun's servers are currently unreachable - laravel

Using laravel I'm trying to send batch emails with the Mailgun api.
$recipients = new Collection();
$subscription_addresses = new Collection();
foreach($request['subscriptions'] as $subscription){
$recipients->put($subscription['email'], (object)array('id' => $subscription['id']));
$subscription_addresses->push($subscription['email']);
}
$recipient_chunks = $recipients->chunk(500);
$subscription_address_chunks = $subscription_addresses->chunk(500);
for($i = 0; $i < count($recipient_chunks); $i++){
$mgClient = Mailgun::create(env('MAILGUN_SECRET'), 'https://' . env('MAILGUN_ENDPOINT'));
$domain = env('MAILGUN_DOMAIN');
$params = array(
'from' => env('MAIL_FROM_NAME') . ' <' . env('MAIL_FROM_ADDRESS') . '>',
'to' => $subscription_address_chunks[$i]->toArray(),
'subject' => $request['newsletterForm']['subject'],
'html' => view('emails.newsletter', $request['newsletterForm'])->render(),
'recipient-variables' => json_encode($recipient_chunks[$i], JSON_FORCE_OBJECT)
);
# Make the call to the client.
$mgClient->messages()->send($domain, $params);
}
The chunking per 500 is because Mailgun queues only 500 mails per request according their docs.
Anyway, while testing with 3 recipients, everything works fine on localhost.
However, while sending on a live domain, I get an error Mailgun's servers are currently unreachable.
Anybody who knows this issue? Not much to find on stackoverflow or in the mailgun docs.
The MX records and mailgun configuration should be ok since I'm able to send single mails on the live site with
Mail::send('emails.confirmation', $request->all(), function($message) use ($request){
$message->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'));
$message->to($request['userInfo']['email'], $request['userInfo']['firstname'] .' '. $request['userInfo']['lastname'])->subject('Uw bestelling bij Hof te Berchemveld');
});

I was facing the same issue & found out that my domain & sender mail domain was different. Now after resolving that issue it worked fine for me.

Related

Relating email replies to original email (e-mail thread) with Sendgrid

I'm sending e-mails with Sendgrid. When the recipients reply to the mails, Sendgrid will parse the reply and POST to my webhook.
How can I relate the reply to the original message, so that I have a message thread?
I'm thinking that this may be possible using X-SMTPAPI headers and unique_args.
Update:
I think this is how I did it (but it was a while ago)
$arguments = ['unique_args' => [
'sentMessage_id' => $this->sentMessage->id,
'tenant_id' => \app('currentTenant')->id,
]];
$header = \json_encode($arguments);
$this->withSwiftMessage(function ($message) use ($header) {
$thread = $this->sentMessage->message->thread;
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $header);
$headers->addTextHeader('References', "<{$thread->first_mail_reference}>");

problem with multiple HTTP requests in Laravel with Guzzle

I'm using Guzzle version 6.3.3. I want to make multiple HTTP requests from an external API. The code shown below worker perfect for me. This is just one single request.
public function getAllTeams()
{
$client = new Client();
$uri = 'https://api.football-data.org/v2/competitions/2003/teams';
$header = ['headers' => ['X-Auth-Token' => 'MyKey']];
$res = $client->get($uri, $header);
$data = json_decode($res->getBody()->getContents(), true);
return $data['teams'];
}
But now I want to make multiple requests at once. In the documentation of Guzzle I found out how to do it, but it still didn't work properly. This is the code I try to use.
$header = ['headers' => ['X-Auth-Token' => 'MyKey']];
$client = new Client(['debug' => true]);
$res = $client->send(array(
$client->get('https://api.football-data.org/v2/teams/666', $header),
$client->get('https://api.football-data.org/v2/teams/1920', $header),
$client->get('https://api.football-data.org/v2/teams/6806', $header)
));
$data = json_decode($res->getBody()->getContents(), true);
return $data;
I get the error:
Argument 1 passed to GuzzleHttp\Client::send() must implement interface Psr\Http\Message\RequestInterface, array given called in TeamsController.
If I remove the $header after each URI then I get this error:
resulted in a '403 Forbidden' response: {"message": "The resource you are looking for is restricted. Please pass a valid API token and check your subscription fo (truncated...)
I tried several ways to set X-Auth-Token with my API key. But I still get errors and I don't know many other ways with Guzzle to set them.
I hope someone can help me out :)
Guzzle 6 uses a different approach to Guzzle 3, so you should use something like:
use function GuzzleHttp\Promise\all;
$header = ['headers' => ['X-Auth-Token' => 'MyKey']];
$client = new Client(['debug' => true]);
$responses = all([
$client->getAsync('https://api.football-data.org/v2/teams/666', $header),
$client->getAsync('https://api.football-data.org/v2/teams/1920', $header),
$client->getAsync('https://api.football-data.org/v2/teams/6806', $header)
])->wait();
$data = [];
foreach ($responses as $i => $res) {
$data[$i] = json_decode($res->getBody()->getContents(), true);
}
return $data;
Take a look at different questions on the same topic (#1, #2) to see more usage examples.

Lumen job dispatching done without database Queue Driver

What do I have:
Lumen service which processing particular Job
Laravel portal which sending file to that service for processing by it
Once it was using only JS and Ajax it worked almost fine - the only what I had to implement is CORS middleware. However after I moved logic to JWT (using jwt-auth package) and GuzzleHttp (I'm using it to send requests to service API) Job stopped processing throught database queue instead it running as if Queue driver being set to sync.
Following is controller which I'm calling during API call:
public function processPackageById(Request $request) {
$id = $request->package_id;
$package = FilePackage::where('id', '=', $id)->where('package_status_id', '=', 1)->first();
if($package) {
Queue::push(new PackageProcessingJob(
$this->firm,
$this->accounts,
$package
));
return 'dispatching done for ' . $id;
}
return 'dispatching not done for ' . $id;
}
where $this->firm and $this->accounts are injected Repositories for particular models. FilePackage object being created on Laravel site and both shares same database to work with.
As result no job being incerted into jobs table. When I use Postman everything is fine. However when I'm trying to send request from Laravel backend:
public function uploaderPost(Request $request)
{
// Here we get auth token and put into protected valiable `$this->token`
$this->authorizeApi();
$requestData = $request->except('_token');
$package = $requestData['file'];
$uploadPackageRequest =
$this->client->request('POST', config('bulk_api.url') .'/api/bulk/upload?token=' . $this->token,
[
'multipart' => [
[
'name' => 'file',
'contents' => fopen($package->getPathName(), 'r'),
'filename' => $package->getClientOriginalName(),
],
]
]);
$uploadPackageRequestJson = json_decode($uploadPackageRequest->getBody()->getContents());
$uploadPackageRequestStatus = $uploadPackageRequestJson->status;
if($uploadPackageRequestStatus == 1) {
$package = BulkUploadPackage::where('id', '=',$uploadPackageRequestJson->id)->first();
// If package is okay - running it
if($package !== null){
// Here where I expect job to be dispatched (code above)
$runPackageRequest =
$this->client->request('POST', config('api.url') .'/api/bulk/run?token=' . $this->token,
[
'multipart' => [
[
'name' => 'package_id',
'contents' => $package->id
],
]
]);
// Here I'm receiving stream for some reason
dd($runPackageRequest->getBody());
if($runPackageRequest->getStatusCode()==200){
return redirect(url('/success'));
}
}
}
return back();
}
Could anyone advise me what is wrong here and what causes the issue?
Thank you!
Alright, it was really interesting. After echoing config('queue.default') in my contoller it appeared that it's value indeed sync nevertheless that I set everything correctly.
Then I assumed that maybe the reason in Laravel itself and its variables. Indeed in .env file from Laravel side QUEUE_DRIVER being set to sync. After I changed it to QUEUE_DRIVER=database everything started working as expected.
Hope that will help someone in future.

IronMq : mail doesn't send but the queue is working

I use IronMQ for to send my email since (laravel framework)
1. for signup email (it's oki with my SMTP and IronMQ)
2. Notification email (between users).
I'm a problem with the n°2 : iron receive the queue and It work but my SMTP don't receive the message for to send it.
I don't understand why because the config SMTP and IronMQ does not change between the two (Mail::queue)
PHP Code :
/****************************
Notification email (buged)
*****************************/
$emailTo = $product->user->email;
$emailFrom = $emailSend;
$data = Input::only('messageSend', 'name');
$data['product'] = $product;
Mail::queue('emails.products.iWant', $data, function($mail) use($emailTo, $emailFrom){
$mail
->from($emailFrom)
->to($emailTo)
->subject("Je suis intéressé(e) par votre produit");
});
/****************************
Signup email (it's oki)
*****************************/
$data = array('id' => $id, 'name' => $name, 'key' => $activation_code);
Mail::queue($view, $data, function($mail) use($email, $subject) {
$mail
->to($email)
->subject($subject);
});
With Mail::queue it's no possible to keep the message_id or it's Success or failed ?
Thanks

php soap client call magento soap v2 api web service login method fail with Error cannot find parameter

magento 1.6, php 5.3.8, windows 7, iis 7.5
follow the sample on mangento but can not get it work.
the old v1 api works though
last request is: string(233) " zzc000 "
last response is: string(294) " SOAP-ENV:ClientError cannot find parameter "
<?php
try{
$proxy = new SoapClient('http://127.0.0.1/Magento1620/index.php/api/v2_soap?wsdl=1', array('trace' => 1, 'connection_timeout' => 120));
$sessionId = $proxy->login("zzc000", "zzc000");
$filters = array(
'sku' => array('like'=>'zol%')
);
$products = $proxy->call($sessionId, 'product.list', array($filters));
var_dump($products);
/*
$proxy = new SoapClient('http://127.0.0.1:50594/webservice1.asmx?WSDL');
var_dump($proxy->HelloWorld());
*/
} catch (Exception $e) {
var_dump($proxy->__getLastRequest());
var_dump($proxy->__getLastResponse());
//echo 'Caught exception: ', $e->getMessage(), "\n";
//var_dump($e->getTraceAsString());
}
?>
please help
thanks
I put web service as WS-I compliant v2 API WSDL
is it going to affect anything?
after a bit research, now i can log in using the following code, but i can not retrieve the products
$sessionId = $proxy->login(array(
'username' => "zzc000",
'apiKey' => "zzc000"
));
but I got the following exception when try to list the products
SOAP-ERROR: Encoding: object has no 'sessionId' property
by using the following code
$filters = array(
'sku' => array('like'=>'zol%')
);
$products = $proxy->catalogProductList($sessionId, $filters);
if you use the v2_soap api, the function call is slightly different. Instead of call() you have to use the camel-cased api method. e.g.:
$products=$proxy->catalogProductInfo($sessionId,$sku);

Resources