Solved

How to delete headers from outgoing smtp message?

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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

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…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

623 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