Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-18-2008, 11:30 AM
Member
 
Join Date: May 2008
Posts: 1
prithviraj is on a distinguished road
Forwarding mails in message/rfc822
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 ...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please wail Message in jsp amar.java JavaServer Pages (JSP) and JSTL 1 04-02-2008 01:29 PM
simulate message box pablitohh New To Java 1 12-05-2007 05:52 PM
How to brodcast a message in the LAN Alpha Networking 1 05-20-2007 05:07 PM
About bean:message yuchuang Web Frameworks 1 05-03-2007 05:50 PM
error message on jsp sandor Web Frameworks 1 04-11-2007 03:10 AM


All times are GMT +3. The time now is 08:17 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org