KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > activation > DataHandler

javax.activation
Class DataHandler

java.lang.Object
  extended byjavax.activation.DataHandler
All Implemented Interfaces:
Transferable
See Also:
Top Examples, Source Code, CommandMap, DataContentHandler, DataSource, URLDataSource

public DataHandler(Object obj,
                   String mimeType)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[873]Send a mail with attachment
By Anonymous on 2005/03/31 00:18:10  Rate
//Send a mail with attachment 
     public static void main ( String [  ]  args )   {  
  
  
         try  {  
             String to = args [ 0 ] ; 
             String from = args [ 1 ] ; 
             String host = args [ 2 ] ; 
             final String username = args [ 3 ] ; 
             final String password = args [ 4 ] ; 
             boolean debug = Boolean.valueOf ( args [ 5 ]  ) .booleanValue (  ) ; 
  
  
             // create some properties and get the default Session 
             Properties props = new Properties (  ) ; 
             props.put ( "mail.smtp.host", host ) ; 
             Session session = Session.getDefaultInstance ( props, 
                     new Authenticator (  )   {  
                         public PasswordAuthentication getPasswordAuthentication (  )   {  
  
  
                             return new PasswordAuthentication ( username, password ) ; 
                          }  
                      }  ) ; 
  
  
             // create a message 
             MimeMessage message = new MimeMessage ( session ) ; 
             // create the from 
             message.setFrom ( new InternetAddress ( from )  ) ; 
             // create the receipient headers 
             InternetAddress [  ]  address =  {  new InternetAddress ( to )   } ; 
             message.setRecipients ( Message.RecipientType.TO, address ) ; 
             // create the subject and date header 
             message.setSubject ( "PurhaseOrder" ) ; 
             message.setSentDate ( new Date (  )  ) ; 
  
  
             // create and fill the first message part 
             MimeBodyPart mbp1 = new MimeBodyPart (  ) ; 
             mbp1.setText ( "Some message text here" ) ; 
  
  
             // create and fill the second message part 
             MimeBodyPart attachment = new MimeBodyPart (  ) ; 
  
  
             // attach the purchaseorder.xml file to the message 
             FileDataSource fds = new FileDataSource ( "attachmentfile.exe" ) ; 
             attachment.setDataHandler ( new DataHandler ( fds )  ) ; 
             attachment.setFileName ( "pattachmentfile.exe" ) ; 
             // create the Multipart and its parts to it 
             Multipart mp = new MimeMultipart (  ) ; 
             mp.addBodyPart ( mbp1 ) ; 
             mp.addBodyPart ( attachment ) ; 
  
  
             // add the Multipart to the message 
             message.setContent ( mp ) ; 
  
  
             // send the message 
  
  
             Transport.send ( message ) ; 
             System.out.println ( "Message delievered" ) ; 
          }  catch  ( Exception mex )   {  
             mex.printStackTrace (  ) ; 
  
  
          }  
      } 


public DataHandler(URL url)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public DataHandler(DataSource ds)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public CommandInfo[] getAllCommands()
See Also:
CommandMap.getAllCommands(java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object getBean(CommandInfo cmdinfo)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public CommandInfo getCommand(String cmdName)
See Also:
CommandMap.getCommand(java.lang.String, java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object getContent()
                  throws IOException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getContentType()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public DataSource getDataSource()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public InputStream getInputStream()
                           throws IOException
See Also:
UnsupportedDataTypeException, DataContentHandler.writeTo(java.lang.Object, java.lang.String, java.io.OutputStream)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getName()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public OutputStream getOutputStream()
                             throws IOException
See Also:
URLDataSource
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public CommandInfo[] getPreferredCommands()
See Also:
CommandMap.getPreferredCommands(java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object getTransferData(DataFlavor flavor)
                       throws UnsupportedFlavorException,
                              IOException
See Also:
ActivationDataFlavor, Transferable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public DataFlavor[] getTransferDataFlavors()
See Also:
Transferable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isDataFlavorSupported(DataFlavor flavor)
See Also:
getTransferDataFlavors(), Transferable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setCommandMap(CommandMap commandMap)
See Also:
CommandMap.setDefaultCommandMap(javax.activation.CommandMap)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setDataContentHandlerFactory(DataContentHandlerFactory newFactory)
See Also:
Error
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void writeTo(OutputStream os)
             throws IOException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags