# Timed Email Sent Multiple Times

**URL:** <https://forum.mautic.org/t/timed-email-sent-multiple-times/8855>\
**Category:** Product Support\
**Created:** [July 2, 2017, 6:35am UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855 "2017-07-02T06:35:41Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [July 2, 2017, 6:35am UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/1 "2017-07-02T06:35:41Z")

</div>

Hi,  
  
  
  
I am having a simple campaign:

1. Send an email on a fixed date  
2. Send another email on another fixed date (one week later)  
  
  
  
Here is the configuration of the campaign:  

- Campaign is based on a campaign with one contact segment  
- Campaign has 2 branches (1 for each email) originating from the contact segment  
- Both email actions have fixed points in time  
- The email actions were marked as marketing emails with 3 send attempts  
  
  
  
**Problem: Today, after the first wave was sent out, I recognized that in some cases the same email was sent out 3 or 2 times (wrong), in some cases 1 time (correct).**  
  
  
  
I experienced something similar with a timed email some weeks ago. Back then I thought I did some misconfiguration. Bur obviously it is a bug.  
  
  
  
Any ideas?  
  
  
  
Peter

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [July 2, 2017, 6:35am UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/2 "2017-07-02T06:35:41Z")

</div>

Hi,

I am having a simple campaign:

1. Send an email on a fixed date
2. Send another email on another fixed date (one week later)

Here is the configuration of the campaign:

- Campaign is based on a campaign with one contact segment
- Campaign has 2 branches (1 for each email) originating from the contact segment
- Both email actions have fixed points in time
- The email actions were marked as marketing emails with 3 send attempts

Problem: Today, after the first wave was sent out, I recognized that in some cases the same email was sent out 3 or 2 times (wrong), in some cases 1 time (correct).

I experienced something similar with a timed email some weeks ago. Back then I thought I did some misconfiguration. Bur obviously it is a bug.

Any ideas?

Peter

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [July 2, 2017, 6:37am UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/3 "2017-07-02T06:37:23Z")

</div>

Addition: The multiple emails are visible in the contact history of the affected contacts. This is really urgent as I will - again - lose contacts because of this.

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [July 2, 2017, 6:38am UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/4 "2017-07-02T06:38:39Z")

</div>

Additions:

- The multiple emails are visible in the contact history of the affected contacts
- I am running Mautic 2.5.1 on this instance
- In the campaign overview the correct number of contacts and emails is visible - in channels/emails the number of sent emails is higher

This is really urgent as I will - again - lose contacts because of this.

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [July 2, 2017, 6:55am UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/5 "2017-07-02T06:55:28Z")

</div>

My impression: When I campaign starts with a timed action, it comes to the faulty behavior. I have another campaign with timed actions - but it starts with an immediate action - there it works fine.

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [July 2, 2017, 7:37am UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/6 "2017-07-02T07:37:09Z")

</div>

Ah shish, could it have something to do with this? [https://github.com/mautic/mautic/issues/3669](https://github.com/mautic/mautic/issues/3669)

My crons run every minute at exactly the same time. ☹

---

<div class="post-metadata">

**Author:** ![kgroves](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kgroves/32/560_2.png) [@kgroves](https://forum.mautic.org/u/kgroves)\
**Post date:** [July 3, 2017, 10:39am UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/7 "2017-07-03T10:39:28Z")

</div>

☹ Yeah I’ve had issues in the past with such things. In the end, and this may not be perfect but works for me, is to set a cron script which detects collisions (so more than one script wont run) that then does each mautic process one after the other. Since doing that I’ve not had any issues.

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [July 4, 2017, 9:31am UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/8 "2017-07-04T09:31:21Z")

</div>

@kgroves Would you mind sharing your cron script? I setup cron with pauses between the different calls. However, a collision detection would be nicer.

---

<div class="post-metadata">

**Author:** ![kgroves](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kgroves/32/560_2.png) [@kgroves](https://forum.mautic.org/u/kgroves)\
**Post date:** [July 4, 2017, 10:36am UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/9 "2017-07-04T10:36:27Z")

</div>

OK its not clever really (I like simple solutions). I will extract it from my private git and post it later. In the meantime the general idea of approach is something like this:

Test for a file existance. eg /tmp/mauticrunning

If not there then create it containing the PID of this process to prevent another running and then go through all of the usual crons one by one. At the end remove the file

If it does exist that means it may be running or its crashed. In that case do a check to see if the PID is still running. If it is then just exit, if not then remove the stale file.

---

<div class="post-metadata">

**Author:** ![kgroves](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kgroves/32/560_2.png) [@kgroves](https://forum.mautic.org/u/kgroves)\
**Post date:** [July 4, 2017, 6:32pm UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/10 "2017-07-04T18:32:12Z")

</div>

Here you are. You may want to adjust to your own use but this should give you the idea for your own:

[https://gist.github.com/kgroveshok/c95a40ed016a4e9dcb208494e62f852d](https://gist.github.com/kgroveshok/c95a40ed016a4e9dcb208494e62f852d)

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [July 5, 2017, 1:06pm UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/11 "2017-07-05T13:06:45Z")

</div>

Thanks for sharing, @kgroves!

But are you sure, this does the trick? As far as I understood, the problem is that  
a) job A must noch overtake itself and  
b) job A and job B must not run parallel.

Your script prevents a but it does not prevent b - or am I wrong?

---

<div class="post-metadata">

**Author:** ![kgroves](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kgroves/32/560_2.png) [@kgroves](https://forum.mautic.org/u/kgroves)\
**Post date:** [July 5, 2017, 2:52pm UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/12 "2017-07-05T14:52:36Z")

</div>

Only use that script as a single cron entry, remove all other cron entries. So what happens is that script (A) will run on whatever time you set, if its not finished by the time another one (B) wants to run then (B) will just abort.

And as each call to the mautic php scripts are in sequence then none of the mautic scripts will not hit one another at any time.

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [July 5, 2017, 6:03pm UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/13 "2017-07-05T18:03:55Z")

</div>

OK, I understand. Then it will work. Thanks again!

---

<div class="post-metadata">

**Author:** ![kgroves](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kgroves/32/560_2.png) [@kgroves](https://forum.mautic.org/u/kgroves)\
**Post date:** [July 6, 2017, 1:17pm UTC](https://forum.mautic.org/t/timed-email-sent-multiple-times/8855/14 "2017-07-06T13:17:10Z")

</div>

Anytime. Let me know if its not working for you though.
