1

I am working on receiving mails in my springboot application. In order to fetch and store the receive mails. I am using imap mail listener. There are two types of mails which I am storing. One is multipart payload type and the other is string payload type.

After receiving mail I am trying to send an auto-generated mails using java mail. The issue which I am facing is worst case scenario of generating auto-reply from my application i.e infinite loop.

Can someone help ow can I differentiate between a normal mail received and auto-reply received in my mail box and generate auto-replies from my system only for those mails which are not auto-reply type.

It would be nice if explained via code for headers check. I came across through few headers like x-Autosubmitted. But they are returning null if I am trying to print the values in console.

  • Can this help @gursimran sondhi : https://www.jitbit.com/maxblog/18-detecting-outlook-autoreplyout-of-office-emails-and-x-auto-response-suppress-header/ and https://stackoverflow.com/questions/1027395/detecting-outlook-autoreply-out-of-office-emails – DebashisDeb Jun 01 '21 at 07:09
  • [3834 section 2](https://datatracker.ietf.org/doc/html/rfc3834#section-2) answers this well. You may also want to read [5230 section 4.6](https://datatracker.ietf.org/doc/html/rfc5230#section-4.6), even if the rest of that document is irrelevant to you. The [60-70 lines that sometimes set wantToReply to false](https://github.com/aox/aox/blob/9730b5f98b43316be1180654f3d3bec24a549ac2/sieve/sieve.cpp#L829) may provide some inspiration. Finally, delaying your own response by half a minute is a fine mitigation in case someone else's autoresponder sucks and there's a loop. – arnt Jun 07 '21 at 16:15

1 Answers1

1

The auto-submmitted markers are described below that you may find helpful:

  • auto-generated - Indicates that a message was generated by an automatic process, and is not a direct response to another message.
  • auto-replied - Indicates that a message was automatically generated as a direct response to another message.
  • auto-notified - Indicates that a message was generated by a Sieve notification system.
  • no - Indicates that a message was NOT automatically generated, but was created by a human. It is the equivalent to the absence of an Auto-Submitted header altogether.

The RFC 2822 states the following:

Though optional, every message SHOULD have a "Message-ID:" field.
Furthermore, reply messages SHOULD have "In-Reply-To:"

So, you may check for the "In-Reply-To:" value in the header.

Also you may add your own value to the outgoing email, so you may distinguish between an automatically generated reply from your system and manually created.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45