Solved

How to delete headers from outgoing smtp message?

Posted on 2008-10-10
1
696 Views
Last Modified: 2013-11-24
Hi,
I developed a java program which can send emails. But when my application send emails it also add some headers(Recieved, Message-ID) which can add some network information. Now my client want to remove that headers.
I did try to remove with the following code but still it adds headers to each and every outgoing message.

So can any one help me with how to remove headers from the outgoing email message?
please...
public static String sendEmail(String body) throws MessagingException 
    {
    	Message message = new MimeMessage(getSession());
    	
        message.addRecipient(MimeMessage.RecipientType.TO, new InternetAddress("krunal117@gmail.com"));
    	message.addFrom(new InternetAddress[] { new InternetAddress("from@example.com") });
    	
    	message.setSubject("Remove Header");
   		message.setContent(body, "text/plain");
   		
   		message.removeHeader("Received");
   		message.removeHeader("Message-ID");
   		message.saveChanges();
   		
    	Transport.send(message);
    	return "success";
    }

Open in new window

0
Comment
Question by:Lolopo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
brunovinicius earned 500 total points
ID: 22837897
Hello,

I'm just writing a little component for JME which connects to an SMTP server via socket and sends an email. Its just a lot lower level than your code, so I know exactly every single byte I sent to the server.

During my tests, I noticed that these headers, and a bunch of others, were simply added to the message even though I barely know of their existence, so that means that they were added by the server itself, and that isn't possible to remove them from the client side.

You can check it by looking onto emails you received in your personal GMail account.
See emails sent by different servers (i.e. Yahoo!, Hotmail, etc), then, on drop down menu on the right upper corner, select "Show Original"). Notice that even messages from the most different servers own such headers.
 
Best Regards,
Bruno Vinicius
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Notify sent to other threads in Java 9 54
Eclipse Help Java EE 5,6,7 Documentation, why not Java EE 8 8 70
Bot application - advice 3 80
dao vs facade design patterns 2 70
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question