Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to delete headers from outgoing smtp message?

Posted on 2008-10-10
1
Medium Priority
?
700 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

783 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