bbottema/simple-java-mail

Support multiple headers with same key

rvman opened this issue · 4 comments

rvman commented

I've run into a situation where I need to be able to apply several headers with the same key to an email, but it seems that the internals for adding headers to an email is defined as a Map, which precludes duplicates.

Is there a way to add the same header multiple times with different values?

Perhaps making the value of EmailBuilder.withHeader() accept a List as the second argument, which would get converted into the same header repeated for each item in the list?

Hi, sorry for the late reply, this report slipped away from me I think.

So you might not need this anymore, but I would like to explore your use case a bit. I can't think of a situation where you would want duplicate headers with different values. I'm not even sure those headers are maintained when sending and reading them back. Can you shed some light on this, please?

rvman commented

Hello,

I've worked around the issue for now, but it would still be a nice to have.

Duplicate headers are maintained through the SMTP transmission process (eg: the "Received" header), so it's certainly a valid use case.

However, in my scenario, we're using an ESP (Email Service Provider), mailgun in this case, that allows us to provide additional tags/metadata on emails we send via their SMTP gateway for analytics purposes.

The header form is basically: "X-Mailgun-Tag: ", with multiple tags specified by simply duplicating the header key and providing different values.

I suspect other ESPs may also have functionality that operates similarly.

Indeed the RFC allows for duplicate optional-field headers, which means any header name other than then ones specified by the RFC.

Released in 6.5.0