Describe the bug
Same Message-ID emails are sent from different processes on our Linux server
To Reproduce
Steps to reproduce the behavior:
two crontab entries are configured on Linux crontab, with same date/time entry
these crontab entries runs Java processes with different java classes created by us
emails are created by our program and sent to us
the content / recipient / subject of these emails are slightly different
when millisecond of these two processes exactly matches with these processes, email's Message-ID will be duplicated
Expected behavior
different Message-ID should be generated from two different processes because it should be globally unique
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
OS: [e.g. iOS]
Browser [e.g. chrome, safari]
Version [e.g. 22]
Smartphone (please complete the following information):
Device: [e.g. iPhone6]
OS: [e.g. iOS8.1]
Browser [e.g. stock browser, safari]
Version [e.g. 22]
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:
add "ProcessID" info to hashcode.id.time part
currentTimeMillis() can be modified to system.nanoTime()
add md5 value of these text to hsahcode.id.time part: [subject]-[destination]-[body text]
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;
It can be modified to followings: