1   package com.eviware.soapui.impl.wsdl.submit.transports;
2   
3   import java.util.Properties;
4   
5   import javax.activation.DataHandler;
6   import javax.activation.FileDataSource;
7   import javax.mail.Message;
8   import javax.mail.Session;
9   import javax.mail.internet.MimeBodyPart;
10  import javax.mail.internet.MimeMessage;
11  import javax.mail.internet.MimeMultipart;
12  
13  import junit.framework.TestCase;
14  
15  public class MimeMessageTestCase extends TestCase
16  {
17     public void testMimeMessage() throws Exception
18     {
19     	Session session = Session.getDefaultInstance( new Properties() );
20  //    Instantiate a Multipart object
21     	MimeMultipart mp = new MimeMultipart();
22  //   	 create the first bodypart object
23     	MimeBodyPart b1 = new MimeBodyPart();
24  //   	 create textual content
25  //   	 and add it to the bodypart object
26     	b1.setContent("Spaceport Map","text/plain");
27     	mp.addBodyPart(b1);
28  //   	 Multipart messages usually have more than
29  //   	 one body part. Create a second body part
30  //   	 object, add new text to it, and place it
31  //   	 into the multipart message as well. This
32  //   	 second object holds postscript data.
33     	MimeBodyPart b2 = new MimeBodyPart(); 
34     	b2.setDataHandler( new DataHandler( new FileDataSource( "project.xml")) );
35     	mp.addBodyPart(b2);
36  //   	 Create a new message object as described above,
37  //   	 and set its attributes. Add the multipart
38  //   	 object to this message and call saveChanges()
39  //   	 to write other message headers automatically.
40     	Message msg = new MimeMessage(session);
41  //   	 Set message attrubutes as in a singlepart
42  //   	 message.
43     	msg.setContent(mp); // add Multipart
44     	msg.saveChanges(); // save changes
45     }
46  }