gmail is modifying header(Message-ID) of incoming mails - java

I sent a mail from my smtp server to gmail.
The message-id that I got is:
Message-ID: SMTPIN_ADDED_BROKEN#mx.google.com>
X-Google-Original-Message-ID:
Gmail appended extra parts in Message-id.
All I got on google that it can be an authentication issue.But source of mail shows:
SPF:PASS
But DKIM is not present in the source.
Do we require DKIM to be necessarily present in the mail's source??
What can I do to prevent header from being modified?

the msesage ID will be modified only if it does not obey RFC standard. so send mail with correct message id format

After many tries, I finally figured out that you need to add brackets enclosing the Message-Id
<yourid#domain.com>

Related

Java SMTP accept badly formatted emails

I am using SubethaSMTP to proxy smtp emails. I have an application sending emails to this proxy.
It happens that sometimes the application send malformed emails (for historical reasons).
This I cannot change. This is a buggy external solutions.
I am handling the received emails and route them based on the email value.
My issue is when I call the following method on the received emails:
Address[] tos = message.getRecipients(RecipientType.TO);
When there are malformed emails in the recipients list, I cannot get the list because I receive an exception.
My objective is to get all the emails and correct the malformed ones.
But because of the exception, I cannot get them.
Is there a way to get all the recipient emails even if there are some bad ones? Just read them without any issue? Is it possible to bypass the controls?
The stack trace is: The email address is #TEST(value) . this is generated by the external application. I'd like to be able to get it, and remove it from the list, and correct it to resend it
javax.mail.internet.AddressException: Missing local name in string ``#TEST''
at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:1216)
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:1096)
at javax.mail.internet.InternetAddress.parseHeader(InternetAddress.java:663)
at javax.mail.internet.MimeMessage.getAddressHeader(MimeMessage.java:733)
at javax.mail.internet.MimeMessage.getRecipients(MimeMessage.java:565)
at MessageHandler.done(TestMessageHandler.java:128)
at org.subethamail.smtp.server.Session.endMessageHandler(Session.java:513)
at org.subethamail.smtp.server.Session.resetMessageState(Session.java:490)
at org.subethamail.smtp.command.DataCommand.execute(DataCommand.java:84)
at org.subethamail.smtp.server.RequireTLSCommandWrapper.execute(RequireTLSCommandWrapper.java:30)
at org.subethamail.smtp.server.CommandHandler.handleCommand(CommandHandler.java:99)
at org.subethamail.smtp.server.Session.runCommandLoop(Session.java:244)
at org.subethamail.smtp.server.Session.run(Session.java:145)

Java Mail api: Read only latest replied message from mail body

I am using JavaMail api to read the mail, but I am facing problem while reading message from the replied mail.
This the the new reply
From: recipient Admin [mailto:test1#test.net]
Sent: 08 August 2016 19:04
To: abcd#test.COM
Subject: commented for test
I want to read only the replied message i.e"this is the new reply",
using
Multipart mp = (Multipart)p.getContent();
gives me the entire mail with the salutations of the sender as well, I want to just read the replied mail and not previous mail salutations.
I don't want differentiate on the basis on specific string as each mailing service would have different salutations.
Thank you!
If you do a bit of searching, you'll find that there's no simple solution to this problem. There is no standard for how the original message is embedded in the reply message and thus no standard way to extract it. The only solution is heuristics that handle the most common forms, but there's no guaranteed way to handle all possible cases.

Java Mail API: Find if a mail is forwarded mail or a reply to another mail

I have a very special requirement
I am using Java Mail API to access a user's Inbox. You can say its like a service inbox for complaints. User registers a complaint by sending an email to this address. I fetch every email from Inbox and create a new complaint. My problem is that I don't want to create unnecessary complaints for reply or forwarded emails. Is there a way to find out that.
Most email clients add Re: or Fwd: to the subject line, but I wouldn't rely on that to determine whether an email is a reply or forwarded text; for example, a German mailclient might put Betr.: in front of the original subject.
Instead, you might want to look at the In-Reply-To: header and/or the References: header. See RFC 4021 for detailed information on those headers.
You can retrieve the headers from a Message by calling the getHeader(java.lang.String) method.
Reading the email header might help, see http://javamail.kenai.com/nonav/javadocs/javax/mail/Part.html#getAllHeaders(). In case of replies, the message header would include:
In-Reply-To: Message-ID of the message that this is a reply to
In case of a forwarded message, selected headers might be preserved. Not as straight-forward as the previous case, but it might still be possible to determine if it was a forwarded message. Refer to http://en.wikipedia.org/wiki/Email_forwarding#Manual_client-based_forwarding for details.

How to get the Exact Mail Address from Lotus Notes Document Using Java API?

I am using document.getItemValueString("INetSendTo") to get the mail address of recipient exact mail address. But some of the mail document I am getting null value. In any other field the email address will be stored?
Email addresses are always stored in the From, SendTo, CopyTo, BlindCopyTo fields.
With certain configurations of the server the corresponding internet email adresses for internal addresses are stored in the INetFrom, INetSendTo, INetCopyTo and INetBlindCopyTo fields.
Actually, you cannot rely on the address fields. According to the SMTP RFCs, messages are to be delivered to the recipients listed in the RCPT TO command string as specified in RFC821, even if all of the headers (To, Cc, Bcc) in the RFC822 messsage are missing or empty. There is a configuration option for Domino to create a BlindCopyTo item for any RCPT TO recipient who was not listed in any of the RFC822 headers, but you cannot assume that this option was enabled at the time the message was received.

JavaMail Issue with From Attribute

I am using JavaMail to send automated emails from my java code. Following is the code I use to set the 'from' and 'to' attribute.
message.setFrom(new InternetAddress("XYZ#company.com", "XYZ's alias"));
message.addRecipients(Message.RecipientType.TO, receiverArray);
where receiverArray is of type InternetAddress[] and contains all the recipients email addresses.
Everything works fine with the functionality and the receiver is receiving the mail but when we open the mail in MS Outlook 2007, the sender is shown as XYZ's alias[XYZ#company.com] and to is shown as the receiver's alias only, may be taken from company's Active Directory on which one can double-click and check the properties.
I need the same to be done for the sender also, i.e. only the alias is shown and not the actual email id.
Maybe some sort of mapping has to be done between the email id I mention in from clause and the active directory.
Both the to and from have registered aliases with the company's Active Directory.
Kindly help.
Thanks in advance.
instead of adding the recipient using a string, try an InternetAddress object. This will give you addresses in RFC 2047 encoding
http://javamail.kenai.com/nonav/javadocs/javax/mail/Message.html#addRecipients(javax.mail.Message.RecipientType, javax.mail.Address[])

Categories

Resources