Hi,

I have raw source of a mail in a text file, I need build a mail and forward that mail to say spam@spam.com.

Conditions are :
* The overall MIME Content-type of the message generated is multipart/mixed.
* Inside this multipart/mixed MIME container is a bodypart of type message/rfc822.
* Inside that message/rfc822 bodypart is the entire message with no alterations, and no headers missed, all the content intact.


I am struggling with content type message/rfc822 , I dont know how to define this content type.

Please someone post me an example or link to an example that uses this content type message/rfc822 to forward a mail , that would be really help-full ..


I developed a standalone java class , at present which is forwarding but the instead of "message/rfc822" its using "application/octet-stream" as content type (I can see that in forwarded message's raw source).

Also forwarded message is going as an attachment is there any possibility that I can send it as any other normal forwarded mail ( i.e the forwarded mail will be included in its original form within the body of the new mail)

My code is here :

package com;

import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendMailUsageNew {

public static void main(String[] args) {

// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String to = "spam@spam.com";
String from = "me@me.com";
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = "my.server.com";

// Create properties for the Session
Properties props = new Properties();

// If using static Transport.send(),
// need to specify the mail server here
props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");

// Get a session
Session session = Session.getInstance(props);

try {
// Get a Transport object to send e-mail
Transport bus = session.getTransport("smtp");

// Connect only once here
// Transport.send() disconnects after each send
// Usually, no username and password is required for SMTP
bus.connect();
//bus.connect("smtpserver.yourisp.net", "username", "password");

// Instantiate a message
Message msg = new MimeMessage(session);

// Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);


msg.setSubject("Fwd:Spam");
msg.setSentDate(new Date());

setFileAsAttachment(msg, "/Users/prithvi/rawSource/onetwothree.tmp0");
msg.saveChanges();
bus.sendMessage(msg, address);

bus.close();

}
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
// How to access nested exceptions
while (mex.getNextException() != null) {
// Get next exception in chain
Exception ex = mex.getNextException();
ex.printStackTrace();
if (!(ex instanceof MessagingException)) break;
else mex = (MessagingException)ex;
}
}
}



// Set a file as an attachment. Uses JAF FileDataSource.
public static void setFileAsAttachment(Message msg, String filename)
throws MessagingException {

try{


// Create and fill first part
MimeBodyPart p1 = new MimeBodyPart();
p1.setText("SPAM message forwarded as an attachment."+"\n");

// Create second part
MimeBodyPart p2 = new MimeBodyPart();

// Put a file in the second part
FileDataSource fds = new FileDataSource(filename);
DataHandler dh2 = new DataHandler(fds);

p2.setDataHandler(dh2);
p2.setFileName(fds.getName());

// Create the Multipart. Add BodyParts to it.
Multipart mp = new MimeMultipart();
mp.addBodyPart(p1);
mp.addBodyPart(p2);
// Set Multipart as the message's content

msg.setContent(mp,"message/rfc822");
}

catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
// How to access nested exceptions
while (mex.getNextException() != null) {
// Get next exception in chain
Exception ex = mex.getNextException();
ex.printStackTrace();
if (!(ex instanceof MessagingException)) break;
else mex = (MessagingException)ex;
}
}


}









}

Thanks in advance ...