KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > mail > internet > MimeBodyPart

javax.mail.internet
Class MimeBodyPart

java.lang.Object
  extended byjavax.mail.BodyPart
      extended byjavax.mail.internet.MimeBodyPart
All Implemented Interfaces:
MimePart, Part
See Also:
Top Examples, Source Code

public void addHeader(String name,
                      String value)
               throws MessagingException
See Also:
MimeUtility, Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[870]Send a mail with attachment
By Anonymous on 2004/11/17 07:38:01  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 (  ) ; 
  
  
          }  
      }  
  
  
  
 //addHeader


public void addHeaderLine(String line)
                   throws MessagingException
See Also:
MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected byte[] content
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected InputStream contentStream
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected DataHandler dh
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Enumeration getAllHeaderLines()
                              throws MessagingException
See Also:
MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Enumeration getAllHeaders()
                          throws MessagingException
See Also:
Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


public String getContentID()
                    throws MessagingException
See Also:
MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String[] getContentLanguage()
                            throws MessagingException
See Also:
MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getContentMD5()
                     throws MessagingException
See Also:
MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected InputStream getContentStream()
                                throws MessagingException
See Also:
content
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getContentType()
                      throws MessagingException
See Also:
DataHandler, Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public DataHandler getDataHandler()
                           throws MessagingException
See Also:
Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getDescription()
                      throws MessagingException
See Also:
Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getDisposition()
                      throws MessagingException
See Also:
headers, Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getEncoding()
                   throws MessagingException
See Also:
headers, MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getFileName()
                   throws MessagingException
See Also:
Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String[] getHeader(String name)
                   throws MessagingException
See Also:
MimeUtility, Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getHeader(String name,
                        String delimiter)
                 throws MessagingException
See Also:
MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


public int getLineCount()
                 throws MessagingException
See Also:
Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Enumeration getMatchingHeaderLines(String[] names)
                                   throws MessagingException
See Also:
MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Enumeration getMatchingHeaders(String[] names)
                               throws MessagingException
See Also:
Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Enumeration getNonMatchingHeaderLines(String[] names)
                                      throws MessagingException
See Also:
MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Enumeration getNonMatchingHeaders(String[] names)
                                  throws MessagingException
See Also:
Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public InputStream getRawInputStream()
                              throws MessagingException
See Also:
getContentStream(), getInputStream()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getSize()
            throws MessagingException
See Also:
Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected InternetHeaders headers
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isMimeType(String mimeType)
                   throws MessagingException
See Also:
Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


public MimeBodyPart(InputStream is)
             throws MessagingException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public MimeBodyPart(InternetHeaders headers,
                    byte[] content)
             throws MessagingException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void removeHeader(String name)
                  throws MessagingException
See Also:
Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setContent(Object o,
                       String type)
                throws MessagingException
See Also:
IllegalStateException, IllegalWriteException, Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setContent(Multipart mp)
                throws MessagingException
See Also:
IllegalStateException, IllegalWriteException, Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setContentID(String cid)
                  throws MessagingException
See Also:
IllegalStateException, IllegalWriteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setContentLanguage(String[] languages)
                        throws MessagingException
See Also:
MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setContentMD5(String md5)
                   throws MessagingException
See Also:
IllegalStateException, IllegalWriteException, MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setDataHandler(DataHandler dh)
                    throws MessagingException
See Also:
IllegalStateException, IllegalWriteException, Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setDescription(String description)
                    throws MessagingException
See Also:
IllegalStateException, IllegalWriteException, Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setDescription(String description,
                           String charset)
                    throws MessagingException
See Also:
IllegalStateException, IllegalWriteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setDisposition(String disposition)
                    throws MessagingException
See Also:
Part.setFileName(java.lang.String), Part.INLINE, Part.ATTACHMENT, IllegalStateException, IllegalWriteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setFileName(String filename)
                 throws MessagingException
See Also:
IllegalStateException, IllegalWriteException, Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setHeader(String name,
                      String value)
               throws MessagingException
See Also:
MimeUtility, Part
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setText(String text)
             throws MessagingException
See Also:
setText(String text, String charset), MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setText(String text,
                    String charset)
             throws MessagingException
See Also:
MimePart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected void updateHeaders()
                      throws MessagingException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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

Popular Tags