KickJava   Java API By Example, From Geeks To Geeks.

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

javax.activation
Class FileDataSource

java.lang.Object
  extended byjavax.activation.FileDataSource
All Implemented Interfaces:
DataSource
See Also:
Top Examples, Source Code, FileTypeMap, MimetypesFileTypeMap

public FileDataSource(File file)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[872]Log into SMTP server to send mail
By Anonymous on 2004/08/25 09:03:12  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 FileDataSource(String name)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getContentType()
See Also:
FileTypeMap.getDefaultFileTypeMap(), DataSource
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


public InputStream getInputStream()
                           throws IOException
See Also:
DataSource
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


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


public void setFileTypeMap(FileTypeMap map)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags