KickJava   Java API By Example, From Geeks To Geeks.

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

javax.mail.internet
Class MimeMultipart

java.lang.Object
  extended byjavax.mail.Multipart
      extended byjavax.mail.internet.MimeMultipart
See Also:
Top Examples, Source Code

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


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


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


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


[197]Use Multipart to send mail
By Anonymous on 2004/10/24 16:03:12  Rate
 
 // Local reference to the javax.mail.Session 
 javax.mail.Session mailSession = null; 
 try  {  
  
  
   Context ctx = new InitialContext (  ) ; 
  
  
   Context myEnv =  ( Context ) ctx.lookup ( "java:comp/env" ) ; 
   String smtpHost =  ( String ) myEnv.lookup ( "smtpHost" ) ; 
   Properties props = new Properties (  ) ; 
   props.put ( "mail.smtp.host", smtpHost ) ; 
  
  
   // Get a mail session. You would normally get this from 
   // JNDI, but some servers have a problem with this. 
   mailSession = javax.mail.Session.getDefaultInstance ( props, null ) ; 
   javax.mail.Message msg = new MimeMessage ( mailSession ) ; 
  
  
   // Set the mail properties 
   msg.setFrom ( new javax.mail.internet.InternetAddress ( email.getFromAddress (  )  )  ) ; 
   InternetAddress [  ]  addresses =   {  
     new InternetAddress ( email.getToAddress (  )  )  
    } ; 
   msg.setRecipients ( javax.mail.Message.RecipientType.TO, addresses ) ; 
   msg.setSubject ( email.getSubject (  )  ) ; 
   msg.setSentDate ( new Date (  )  ) ; 
  
  
   // Create the body text 
   Multipart parts = new MimeMultipart (  ) ; 
   MimeBodyPart mainBody = new MimeBodyPart (  ) ; 
   mainBody.setText ( email.getBody (  )  ) ; 
   parts.addBodyPart ( mainBody ) ; 
  
  
   // Could also have supported attachments, but not for this version 
  
  
   // it's commented it out. 
  
  
   /* 
   MimeBodyPart attachmentBody = new MimeBodyPart (  ) ; 
   attachmentBody.setText (  "This is text in the attachment"  ) ; 
   attachmentBody.addBodyPart (  p2  ) ; 
   */
 
  
  
   // Set some header fields 
   msg.setHeader ( "X-Priority", "High" ) ; 
   msg.setHeader ( "Sensitivity", "Company-Confidential" ) ; 
   msg.setContent ( parts ) ; 
   System.out.println ( "Sending mail to " + email.getToAddress (  )  ) ; 
   Transport.send ( msg ) ; 
  }  
  
  
 //ds


public BodyPart getBodyPart(int index)
                     throws MessagingException
See Also:
Multipart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public BodyPart getBodyPart(String CID)
                     throws MessagingException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getCount()
             throws MessagingException
See Also:
Multipart.parts
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


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


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


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


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


public void setSubType(String subtype)
                throws MessagingException
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:
Multipart
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags