I have a SAP HCI scenario where I send in the end an email with a XML response attached. I get this error although the file has 20kb size and it has only one receiver.
com.sun.mail.smtp.SMTPSendFailedException: 552 5.3.4 Header size exceeds fixed maximum size
Ok, I understood it:
It's SMTP adapter channel-specific configuration. By design developer must choose source of an attachments and headers the only good choice (not properties, that's pity).
All the headers of CPI message are transfered to SMTP (bad design for me), so your limitation occurs due either specified attachment or any other header.
For proving my hypothesis, I created two headers: aa with small length and ab with long text:
msg.setHeader('aa', "<?xml version='1.0'?><root>" + "a"*256 + "</root>")
msg.setHeader('ab', "<?xml version='1.0'?><root>" + "a"*1024*30 + "</root>")
Then, I posted the message into cloud-internal SMTP, and received bounce message:
This message was created automatically by the SMTP relay on XXXXXXXXXXXXXXXX.
A message that you sent could not be delivered to all of its recipients.
The following address(es) failed:
ilya.kuznetsov@domain
SMTP error from remote mail server after MAIL FROM:<ilya.kuznetsov@domain> SIZE=4019:
host XXXXXXXXXXXX [1.1.1.1]: 550 Administrative prohibition 2017-11-03-121-56439fc44a7dc0b43c28074ed7efe877
------ This is a copy of the message, including all the headers. ------
Return-path: <ilya.kuznetsov@domain>
...
Date: Fri, 3 Nov 2017 12:00:20 +0000 (UTC)
From: ilya.kuznetsov@domain
To: ilya.kuznetsov@domain
Subject: Hello world 2017-11-03T12:00:19.019Z
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_69_482225443.1509710419985"
aa: <?xml version='1.0'?><root>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</root>
ab: <?xml version='1.0'?><root>aaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</root>
SAP_MessageProcessingLogID: AFn8WlOMHKwYXS0KJbCcva0BG9Wh
SAP_MplCorrelationId: AFn8WlOmx_9yZFXocsPbBYIjesC9
SAP_PregeneratedMplId: AFn8WlPK-r5wMnCqVPDM-nHhsvmo
scriptFile: stackoverflow_47077818.groovy
scriptFileType: groovy
------=_Part_69_482225443.1509710419985
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Hello world body
------=_Part_69_482225443.1509710419985
Content-Type: application/xml; name=aa
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=aa
<?xml version='1.0'?><root>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</root>
------=_Part_69_482225443.1509710419985--
So, as you can see, unrelated headers which are not used for the letter, transfered during SMTP session and they could be the reason of your error.
The better way is to use simple Groovy script with plain Javamail code.