Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sending attatchments....

843830Jul 26 2002 — edited Aug 26 2002
hi all,

Im developing a webmail and i've seen on the net about how to send an attatchment in mail..i found this.....



try {
String text="This is the file attachment";
// create a message
Message msg = new MimeMessage(mailsession);
Address fromAddress=new InternetAddress(from);
// set the from
msg.setFrom(fromAddress);
InternetAddress[] address ={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subj);
MimeBodyPart textPart = new MimeBodyPart();
textPart.setContent(text, "text/plain");
File f = new File(filename);
MimeBodyPart attachFilePart = new MimeBodyPart();
FileDataSource fds = new FileDataSource(f);
attachFilePart.setDataHandler(new DataHandler(fds));
attachFilePart.setFileName(fds.getName());
Multipart mp = new MimeMultipart();
mp.addBodyPart(textPart);
mp.addBodyPart(attachFilePart);
msg.setContent(mp);
Transport.send(msg);
out.println("Your attachment has been sent successfully");

}
catch (Exception e)
{
System.out.println(e);
}

....
but this is code tries to send the files from the server wright... so before sending a mail with attatchments...we need to upload the file to the webserver and then send the email with attatchment...so i just want to know is this wright way of sending mails with attatchments...

any inputs on this..

kiran




Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 23 2002
Added on Jul 26 2002
1 comment
105 views