Did the lead reply to email?

I got this idea on how to monitor if a lead replied to an email:




  1. We use Mailgun to send emails out, and also have MX records for Mailgun to read incoming emails for a certain subdomain


  2. Every email Mautic sends out gets sent over Mailgun using that subdomain - e.g., if I want to send as denis.pavliha@domain.si I send as denis.pavliha@sub.domain.si instead, and the lead will then reply to denis.pavliha@sub.domain.si


  3. When Mailgun receives a reply to denis.pavliha@sub.domain.si, I set up a route that filters messages that are sent to @sub.domain.si and forwards them to denis.pavliha@domain.si and at the same time, I trigger a webhook using Mailgun where all the email data (to, from, body, subject,ā€¦) are included.


  4. I capture this Mailgunā€™s webhook using a custom-developed API that reads the From: field (so that I know which Mautic lead/contact I need to bind it to), and finally use this same API to inject a custom event into Mautic (to this lead).



    What do you guys think? Does it make sense?



    Whereas this last part of inserting data as custom event bound to a certain lead still bothers meā€¦ I donā€™t want to use forms and instead want to generate an event that can be shown under contacts (the same way a ā€˜contact identifiedā€™ or ā€˜page visitedā€™ is shown). I have looked at many SQL tables (I have a self-hosted instance, of course) but still havenā€™t found a way to manage this task. Otherwise, the above described points 1 to 3 (and first part of 4) work as expected.



    I am really looking forward towards any feedback, either way.



    Best,

    D.

I got this idea on how to monitor if a lead replied to an email:

  1. We use Mailgun to send emails out, and also have MX records for Mailgun to read incoming emails for a certain subdomain

  2. Every email Mautic sends out gets sent over Mailgun using that subdomain - e.g., if I want to send as denis.pavliha@domain.si I send as denis.pavliha@sub.domain.si instead, and the lead will then reply to denis.pavliha@sub.domain.si

  3. When Mailgun receives a reply to denis.pavliha@sub.domain.si, I set up a route that filters messages that are sent to @sub.domain.si and forwards them to denis.pavliha@domain.si and at the same time, I trigger a webhook using Mailgun where all the email data (to, from, body, subject,ā€¦) are included.

  4. I capture this Mailgunā€™s webhook using a custom-developed API that reads the From: field (so that I know which Mautic lead/contact I need to bind it to), and finally use this same API to inject a custom event into Mautic (to this lead).

What do you guys think? Does it make sense?

Whereas this last part of inserting data as custom event bound to a certain lead still bothers meā€¦ I donā€™t want to use forms and instead want to generate an event that can be shown under contacts (the same way a ā€˜contact identifiedā€™ or ā€˜page visitedā€™ is shown). I have looked at many SQL tables (I have a self-hosted instance, of course) but still havenā€™t found a way to manage this task. Otherwise, the above described points 1 to 3 (and first part of 4) work as expected.

I am really looking forward towards any feedback, either way.

Best,
D.

1 Like

I think I got itā€¦ php+mysqli

[code]// Mautic event data

$payload = Array(
	"email" => $email,
	"utm_medium" => "email",
	"utm_source" => "email",
	"utm_campaign" => $subject,
	"email_body" => $body
);  



// Mautic query

$data = 'a:' . count($payload) . ':{';

foreach ($payload as $key => $value)
{
	$data .= 's:' . strlen($key) . ':"' . $key . '";' . 's:' . strlen($value) . ':"' . $value . '";'; 
}

$data .= '}'; 



// Inject event into lead's timeline

$query = "INSERT INTO `lead_utmtags`(`id`, `lead_id`, `date_added`, `query`, `referer`, `remote_host`, `url`, `user_agent`, `utm_campaign`, `utm_content`, `utm_medium`, `utm_source`, `utm_term`) VALUES (0, (SELECT id FROM leads WHERE email='$email' ORDER BY date_added DESC LIMIT 0,1), NOW(), '$data', NULL, NULL, '', NULL, '$subject', NULL, 'email', 'email', NULL)";
mysqli_query($con, $query);



// Update lead's last activity

$query = "UPDATE leads SET last_active=NOW() WHERE email='$email'";
mysqli_query($con, $query);

[/code]

I can now see if a lead replied to an email within Mautic using UTM tags:

Still looking forward if any of you may provide some feedback or e.g. a better practice.

Best regards,
D.

Wow, great implementation. I am looking to begin to customize mautic. This is a good template.

Yeah, there are however some drawbacks:

Best,
D.

Hi Denis, this sure is ingenious - but isnt there any internal controller function that could be invoked to register these stats? I guess youā€™ve been looking for something similar - have you found something yet?

I 'd love to see someone in the community to share what they think as well.

Hi,

as mentioned in this conversation:

[quote=26613:@denispavliha]The drawback is that itā€™s a workaround (not a proper solution) and canā€™t be used for decisions in campaigns.

To use it as a decision point, my code should be changed that instead of writing into DB, it should call Mauticā€™s REST API and add the lead (identified by the email) to a campaign where you can continue with activities (it is doable for sure).[/quote]

So I would suggest to re-code that API which writes directly to DB, and instead call the Mautic REST APIā€™s endpoint that best suits the case (e.g. add to segment, or.modify stage, or add to campaign, ā€¦).

Best,
D.