PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label mailgun. Show all posts
Showing posts with label mailgun. Show all posts

Friday, November 4, 2022

[FIXED] When use AWS Lambda to process mails from mailgun, can't get mails in JSON format

 November 04, 2022     amazon-web-services, email, json, lambda, mailgun     No comments   

Issue

What I am tried to do is to have a lambda function proccess emails forwarded by mailgun.

So far, I have setup mailgun's route so it will forward emails to a AWS api gateway, then the api gateway triggers a lambda function.

The problem comes when I try to process the mail, instead of getting a pretty Json that I am expecting inside the lambda's event.body, I m getting raw post form data like

--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent-Disposition: form-data; name=\"Content-Type\"\r\n\r\nmultipart/mixed; boundary=\"001a1140216cee404d05440c49e7\"\r\n--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent-Disposition: form-data; name=\"Date\"\r\n\r\nTue, 20 Dec 2016 13:40:53 +1300\r\n--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent ......

My question is, what should I do to get the JSON version of the forwarded emails in lambda?


Solution

Not sure if you ever came to a solution, but I have this working with the following settings.

  1. Setup your API Gateway method to use "Use Lambda Proxy integration"
  2. In your lambda (I use node.js) use busboy to work through the multi-part submission from mailgun. (use this post for help with busboy Busboy help)
  3. Make sure that any code you are going to execute after all busboy is complete is executed in the 'finish' portion of the busboy code.


Answered By - Greg Fennell
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, July 7, 2022

[FIXED] How to use a custom SMTP settings in my WordPress site

 July 07, 2022     email, mailgun, phpmailer, smtp, wordpress     No comments   

Issue

I need to use custom SMTP settings for my WordPress site to send email through my email servers such as Mailgun or SendGrid.


Solution

Place this in your theme function.php or your own plugin.

add_action( 'phpmailer_init', 'custom_phpmailer_init' );
function custom_phpmailer_init( $phpmailer ) {

    $phpmailer->isSMTP();
    $phpmailer->Host = 'smtp.mailgun.com';
    $phpmailer->Port = 465;
    $phpmailer->Username = 'user_name';
    $phpmailer->Password =  '********';
    $phpmailer->SMTPAuth = true;
    $phpmailer->SMTPSecure = 'ssl';
    $phpmailer->From       = 'FromName@example.com';
    $phpmailer->FromName   = 'FromName';

}


Answered By - Mohamed Ali O.Ameur
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, February 7, 2022

[FIXED] Laravel won't pass my domain to the MailGun driver so I can't send mail

 February 07, 2022     email, laravel, mailgun, php     No comments   

Issue

This may not be a problem with MailGun as I was unable to send via Gmail aswell.

The error i'm getting as seen below you can see where the domain should be passed but hasn't.

POST https://api.mailgun.net/v3//messages.mime

the domain should be

POST https://api.mailgun.net/v3/domin/messages.mime

I know I have Guzzle installed, I have restated the web server and i know my details are correct. I'v created a test project to do only mail aswell to no avail.

Could it be something todo with my host computer (macbook air) or that fact i'm using the development web server

 php artisan serve

I'm new to Laravel so i'm unsure of anything else I can do.

services.php

  'mailgun' => [
        'domain' => env('sandbox*****.mailgun.org'),
        'secret' => env('key-**************'),
    ],

mail.php

'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
 'port' => env('MAIL_PORT', 587),
'from' => ['address' => null, 'name' => null],
 'encryption' => env('MAIL_ENCRYPTION', 'tls'),
 'username' => env('postmaster@sandbox***********.mailgun.org'),
  'password' => env('sandboxpassword'),
 'sendmail' => '/usr/sbin/sendmail -bs',
 'pretend' => env('MAIL_PRETEND', false),

A've stopped using the env file so it defaults to the mail.php, but when the attributes are the same details it's the same outcome. And yeah just incase its asked i'm aware you need to restart the server when you've changed the .env and just to be on the safe site i've been doing it when changing the mail.php or services.php

TestController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Mail;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class TestController extends Controller
{
    public function index() {
        Mail::raw('Text to e-mail', function ($message) {
            $message->from('us@example.com', 'Laravel');

            $message->to('dksnowdon@gmail.com');
        });

        return view('welcome');
    }
}

the exact error

ClientException in RequestException.php line 107:
Client error: `POST https://api.mailgun.net/v3//messages.mime` resulted in a `404 NOT FOUND` response:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested (truncated...)
in RequestException.php line 107
at RequestException::create(object(Request), object(Response)) in Middleware.php line 65
at Middleware::GuzzleHttp\{closure}(object(Response)) in Promise.php line 199
at Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) in Promise.php line 152
at Promise::GuzzleHttp\Promise\{closure}() in TaskQueue.php line 60
at TaskQueue->run(true) in Promise.php line 240
at Promise->invokeWaitFn() in Promise.php line 217
at Promise->waitIfPending() in Promise.php line 261
at Promise->invokeWaitList() in Promise.php line 219
at Promise->waitIfPending() in Promise.php line 62
at Promise->wait() in Client.php line 129
at Client->request('post', 'https://api.mailgun.net/v3//messages.mime', array('auth' => array('api', null), 'multipart' => array(array('name' => 'to', 'contents' => 'dksnowdon@gmail.com'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <us@example.com> To: dksnowdon@gmail.com MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Text to e-mail', 'filename' => 'message.mime')))) in Client.php line 87
at Client->__call('post', array('https://api.mailgun.net/v3//messages.mime', array('auth' => array('api', null), 'multipart' => array(array('name' => 'to', 'contents' => 'dksnowdon@gmail.com'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <us@example.com> To: dksnowdon@gmail.com MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Text to e-mail', 'filename' => 'message.mime'))))) in MailgunTransport.php line 79
at Client->post('https://api.mailgun.net/v3//messages.mime', array('auth' => array('api', null), 'multipart' => array(array('name' => 'to', 'contents' => 'dksnowdon@gmail.com'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <us@example.com> To: dksnowdon@gmail.com MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Text to e-mail', 'filename' => 'message.mime')))) in MailgunTransport.php line 79
at MailgunTransport->send(object(Swift_Message), array()) in Mailer.php line 85
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php line 395
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 181
at Mailer->send(array('raw' => 'Text to e-mail'), array(), object(Closure)) in Mailer.php line 133
at Mailer->raw('Text to e-mail', object(Closure)) in Facade.php line 219
at Facade::__callStatic('raw', array('Text to e-mail', object(Closure))) in TestController.php line 17
at Mail::raw('Text to e-mail', object(Closure)) in TestController.php line 17
at TestController->index()

Solution

You need to leave the services.php config as default:

'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
    ],

Then in the .env you need to put:

MAILGUN_DOMAIN=yourdomain
MAILGUN_SECRET=yoursecret


Answered By - kEpEx
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing