Skip to content

Mailgun send multiple emails instead of 1 #3651

Closed
@rferbesa

Description

@rferbesa

Hello!
I have a problem I've asked in Stackoverflow and ServerFault several weeks ago with no answer, so this is my last chance to find the solution. I'll try to follow the steps to describe this "bug".

Issue Description

I migrated from Parse to Parse Server hosted in Digital Ocean (details below) and everything seemed to be working ok until I realized there was a problem sending emails (from the app through Cloud code and from Parse Server for email verification after the registration): the emails are sent multiple times, usually twice but sometimes 3, 4 even 5 or 6 times.

Steps to reproduce

I'm not sure what are the steps, but this is my code and configuration:

Parse Server configuration > myparseuser/cloud/main.js

var api_key = 'key-myMailgunkey';
var domain = 'mg.mydomain.com';
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
 Parse.Cloud.define("functiontosendemail", function(request, response) {
                   var name = request.params.username;
                   var email = request.params.email;
                   var body = request.params.body;
            var data = {
              from: email,
              to: '[email protected]',
              subject: "Contact Form",
              text: body
               };
        mailgun.messages().send(data, function (error, body) {
              console.log(body);
        });
});

Parse Server configuration > myparseuser/index.js

...
var api = new ParseServer({  
  ...,
  emailAdapter: {
    module: 'parse-server-simple-mailgun-adapter',
    options: {
      fromAddress: '[email protected]',
      domain: 'mg.mydomain.com',
      apiKey: 'key-myMailgunkey'
    }
  }
});
...

Mailgun configuration:

Domain: mg.mydomain.com
State: Active
IPAddress: someipaddress
SMTP Hostname: smtp.mailgun.org
Default SMTP Login: [email protected]
Default password: defaultpassword #Note: I don't remember to use this password anywhere.
API Base URL: https://api.mailgun.net/v3/mg.mydomain.com
API Key: key-myMailgunkey
Inbound smap filter: Disabled
Wildcard domain: Off
DKIM selector: pic
Tracking hostname: email
Click tracking: Off
Open tracking: Off
Unsubscribes: Off
TLS Connection: Opportunistic
Certificate verification: Required
TXT record mg.mydomain.com (ok)
TXT record pic._domainkey.mg.mydomain.com (ok)
CNAME record email.mg.mydomain.com (checked)
MX records mxa.mailgun.org (checked)
MX records mxb.mailgun.org (checked)

Expected Results

I expected that each verification email was sent only once, and each contact email (via CloudCode) was sent only once.

Actual Outcome

Each email is sent usually twice but sometimes 3, 4, 5 or 6 times.

Environment Setup

  • Server

    • parse-server version 2.3.1
    • Operating System: Ubuntu 16.041
    • Hardware: 512MB RAM, 2GB Disk
    • Localhost or remote server? Digital Ocean
  • Database

    • MongoDB version: 3.0.14
    • Storage engine: Linux
    • Hardware: 512MB RAM, 2GB Disk
    • Localhost or remote server? Digital Ocean

Logs/Trace

If I send and email from the app calling "functiontosendemail" in rare occasions the email is sent and received only once. Usually the email is sent and received between 3 and 8 times In these cases, after more or less 1 minute my app receives from Parse Server this error:

com.parse.ParseRequest$ParseRequestException: i/o failure

Mailgun Log shows this two actions between 3 and 8 times:

Accepted: [email protected][email protected] 'Contact Form'
Delivered: [email protected][email protected] 'Contact Form'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions