0

I am using Liferay mail (MailServiceUtil/MailEngine) to send mails to users. I have configured mail in ServerAdministration > Mail . My code is as below:

    InternetAddress toAddress = new InternetAddress(emailTo);            
    InternetAddress fromAddress = new InternetAddress("XXXXXXX","XX");
    MailMessage mailMessage = new MailMessage();
    mailMessage.setTo(toAddress);
    mailMessage.setFrom(fromAddress);
    mailMessage.setSubject(subject);
    mailMessage.setBody(emailbody);
    mailMessage.setHTMLFormat(true);
    MailServiceUtil.sendEmail(mailMessage);

Below information is sent by above code:

Received: from hostname ([UNAVAILABLE]. [XXX.XXX.XXX])

And

Message-ID: <1567646772.21541142172709.JavaMail.user@hostname>

I got method to change message id but i am not able to change hostname (hostname to localhost).

I have tried to set mail.session.mail.smtp.localhost=localhost by adding Manually specify additional JavaMail properties to override the above configuration or portal-ext.propeties. But no success. Please help to set this as localhost.

Varun Arya
  • 335
  • 1
  • 14

2 Answers2

1

I believe you're speaking of mail headers like this:

Received: from host.example.com ([x.x.x.x]) by anotherhost.example.com
 (anotherhost [y.y.y.y]) with ESMTPS (Nemesis) id blablablabla;
 Thu, 01 Nov 2018 11:07:15 +0100

AFAIK, they're added by the next one up in the chain - e.g. your Liferay server is the originator, and didn't receive the mail from anyone, but it forwards to the next hop in the list of mail handlers. That server, the next hop, adds information about the origin of this email - so it's safely out of your control on the Liferay or Javamail side.

The message id is something that's generated to be unique, and it's possible to override the default (that's what you got). The protocol of systems that have forwarded this mail is built by the next system, thus not overridable on the originating system.

Edit (reaction to your comment):

Even if there's a way to have the last machine in the list identify as "localhost", what good is it really? The next hop up will correctly give the machine's IP address and reverse-lookup hostname. And you'll only make debugging harder, if you need to figure out, which "localhost" a mail has originated on. Remember: You'll have at least as many localhosts in your network as you have machines (in total, the sum of VMs, Containers, bare metal)

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • Thanks for the help. I found "mail.smtp.localhost - String Local host name. Defaults to InetAddress.getLocalHost().getHostName(). Should not normally need to be set if your JDK and your name service are configured properly. ". And this worked for me. But liferay is not replacing this by setting mail.session.mail.smtp.localhost=localhost or mail.smtp.localhost=localhost. – Varun Arya Nov 02 '18 at 09:30
  • Ok, you might find a way... see my edit - I'm not understanding the reason for this requirement, it'll only make your life harder – Olaf Kock Nov 02 '18 at 09:52
  • It might be security concern. A user is getting our user@hostname in his mail header received by him. – Varun Arya Nov 02 '18 at 10:04
  • Well, you said you solved the message-id problem and only have the hostname in your delivery. As I said: Next up in the chain, you can't do anything about it on the system originating the mail (you'd need to patch that upstream mail relay to hide the originating system). The hostname doesn't need to be internet-reachable and should be firewalled anyways. And, as it's your Liferay server anyways: You probably already allow traffic to it, even without any regular user knowing the internal hostname. Unless you give more details, I'd call this a non-issue – Olaf Kock Nov 02 '18 at 12:59
  • Thanks of the help Olaf. – Varun Arya Jun 13 '19 at 09:16
0

The Message-ID is derived from the results of InternetAddress.getLocalAddress, which you can completely control by setting the mail.from property.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40