API not sending emails to existing contacts

I don’t understand why this was being closed as not being a bug, but that’s probably just me… :slight_smile:
API not sending emails to existing contacts · Issue #14957 · mautic/mautic

This used to work fine with older Mautic installation but doesn’t work correct with Mautic 6.0.0 anymore:

Mautic Series

6.0.x series

Mautic installed version

6.0.0

Way of installing

I downloaded a release from https://www.mautic.org/mautic-releases

PHP version

8.2.21

What browsers are you seeing the problem on?

No response

What happened?

We are using the Mautic API to send emails to our users.
One of the emails we send is when a user account is being created, the user should get 2 emails, 1 with their username + instructions and 1 with their password.

In our script we check if a contact with that email exists.

NO: → Create a new contact, send the email(s), delete the contact
YES: - >Send the email(s)

The issue we’re running into now:
Keeping the new user account above as an example (should get 2 emails).

Contact does NOT exist within Mautic

  • Contact is being created by our script (works fine)
  • First email with username and instructions is being sent (works fine and also see it in Reports)
  • Second email with password is being sent (this does NOT work, also do not see the email in Reports)
  • Contact is being deleted by our script (works fine)

Contact DOES exist within Mautic

  • First email with username and instructions is being sent (this does NOT work, also do not see the email in Reports)
  • Second email with password is being sent (this does NOT work, also do not see the email in Reports)

We had an older instance of Mautic (version 4.4.7) and it was working fine there.

How can we reproduce this issue?

Step 1: Sent an email through the API using an existing contact

Would be interesting to see the API call to understand. Also if you have any errors, that helps.

Hello, sorry for the late reply but I was sick.

I cannot share the code, but it’s a very simple Powershell script which used to work fine.
The API call being done:

        $EmailUsername = "$MailUri/4/contact/$Contact_ID/send"
        --SOME LOGGING HERE--
        $Body = @{
            tokens = @{
                -- 2 TOKENS HERE TO DEFINE EMAIL SUBJECT AND BODY --
            }
            assetAttachments = @{
                attachment_one = 1
            }
        }
    
        $Parameters = @{
            Method = "POST"
            Uri = $EmailUsername
            Headers = $Header
            Body = ($Body | ConvertTo-Json)
            ContentType = "application/json"
        }
        
        Try {
            Invoke-RestMethod @Parameters
            --SOME LOGGING HERE--
        }
        Catch {
            --SOME LOGGING HERE--
            Exit 1
        }

There is no error at all, Mautic is reporting the email to be sent out while it’s not.
Like I said in the original post, if a new contact is being created the contact gets one email (should get two) and when a contact already exists, the contact gets none (should get two).

Hi,
next steps to troubleshoot this:

  1. Reponse
    Do you get a json ‘{ “success”: 1 }’ response?

  2. Can you check if the contact is not DNC you are trying to send? (Red icon next to the name). It happens often that you try with some dummy email, it bounces and can’t send email to the same person again

  3. Is there a setting in your Mautic at Email Settings > Frequency - max 1 email / day?

Joey

1: Yes
2: No
3: No

Is it possible, that password has special characters that crashes your script?
Joey

No the script runs fine, we also get the response from Mautic that the emails have been sent, but they just do not get sent out.