Solved

How to delete headers from outgoing smtp message?

Posted on 2008-10-10
1
681 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
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now