java.lang.Object
javax.mail.Multipart
- Direct Known Subclasses:
- MimeMultipart
- See Also:
- Top Examples, Source Code
public void addBodyPart(BodyPart part)
throws MessagingException
- See Also:
- IllegalWriteException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[871]Login into SMTP server and send mail
By Anonymous on 2004/08/25 09:02:51 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 void addBodyPart(BodyPart part,
int index)
throws MessagingException
- See Also:
- IllegalWriteException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected String contentType
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BodyPart getBodyPart(int index)
throws MessagingException
- See Also:
- IndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[875]Display the conent of a mail message
By Anonymous on 2004/08/25 09:27:45 Rate
// Display the conent of a mail message
Part messagePart=message;//Get message from somewhere else
Object content=messagePart.getContent ( ) ;
for ( int i=0;i < ( ( Multipart ) content ) .getCount ( ) ; i++ ) {
messagePart= ( ( Multipart ) content ) .getBodyPart ( i ) ;
InputStream is = messagePart.getInputStream ( ) ;
BufferedReader reader =new BufferedReader (
new InputStreamReader ( is ) ) ;
String thisLine=reader.readLine ( ) ;
while ( thisLine!=null ) {
System.out.println ( thisLine ) ;
thisLine=reader.readLine ( ) ;
}
}
} catch ( Exception ex ) {
ex.printStackTrace ( ) ;
}
public String getContentType()
- See Also:
contentType
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int getCount()
throws MessagingException
- See Also:
parts
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Part getParent()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected Multipart()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected Part parent
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected Vector parts
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void removeBodyPart(int index)
throws MessagingException
- See Also:
- IllegalWriteException, IndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean removeBodyPart(BodyPart part)
throws MessagingException
- See Also:
- IllegalWriteException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected void setMultipartDataSource(MultipartDataSource mp)
throws MessagingException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void setParent(Part parent)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract void writeTo(OutputStream os)
throws IOException,
MessagingException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples