关于JAVAMAIL(100分)

  • 主题发起人 主题发起人 Tony_yan
  • 开始时间 开始时间
T

Tony_yan

Unregistered / Unconfirmed
GUEST, unregistred user!
有谁会用JAVAX.MAIL发送带附件的邮件,有没有例子,给兄弟一个,万分感谢!!
 
不会吧,没有高手?
可惜我不是高手!
 
Here is the code to send an attachment,try it.
Good lucky!:
// create mime message object
// set the required parameters
MimeMessage message = createMessage(to, cc, subject);

// create the message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
//fill message
messageBodyPart.setText(msg);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// fill the array of files to be attached
File [] attachments = { .... };
for( int i = 0;
i < attachments.length;
i++ )
{
messageBodyPart = new MimeBodyPart();
FileDataSource fileDataSource =new FileDataSource(
attachments);
messageBodyPart.setDataHandler(new DataHandler(
fileDataSource));
messageBodyPart.setFileName(
attachments.getName());

multipart.addBodyPart(messageBodyPart);
}
// add the Multipart to the message
message.setContent(multipart);
// SEND THE MESSAGE
Transport.send( message );
 
如果你下载javamail包,那里面都有了,例子全的很
 
接受答案了.
 
后退
顶部