Solved

How to delete headers from outgoing smtp message?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web application structure 18 111
How do I remove an object from a 3 51
What's wrong with this code? 4 34
ejb mdb examples 1 19
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

740 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