jakartaee / mail-api

Jakarta Mail Specification project
https://jakartaee.github.io/mail-api
Other
247 stars 101 forks source link

Duplicated Message-ID #595

Open pentasan opened 2 years ago

pentasan commented 2 years ago

Describe the bug Same Message-ID emails are sent from different processes on our Linux server

To Reproduce Steps to reproduce the behavior:

Expected behavior

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Mail server: SMTP

Additional context

Following is the source code that generates Message-ID: UniqueValue class: public static String getUniqueMessageIDValue(Session ssn) { String suffix = null;

InternetAddress addr = InternetAddress.getLocalAddress(ssn);
if (addr != null)
    suffix = addr.getAddress();
else {
    suffix = "jakartamailuser@localhost"; // worst-case default
}
int at = suffix.lastIndexOf('@');
if (at >= 0)
    suffix = suffix.substring(at);

StringBuilder s = new StringBuilder();

// Unique string is <hashcode>.<id>.<currentTime><suffix>
s.append(s.hashCode()).append('.').
  append(id.getAndIncrement()).append('.').
  append(System.currentTimeMillis()).
  append(suffix);
return s.toString();
}

It can be modified to followings:

oliverlietz commented 2 years ago

@pentasan You can set the mail header Message-ID yourself to fix the issue.

jmehrens commented 2 years ago

This will be fixed with the implementation of https://github.com/eclipse-ee4j/mail/issues/460