Results 1 to 3 of 3
  1. #1
    balaji csc is offline Member
    Join Date
    Nov 2009
    Posts
    10
    Rep Power
    0

    Default Sending Attached Excel via mail

    Hi,
    Could you please help me........
    I want to send attached Excel file through Java Mail. For Example My Excel file is located in c:\\testing folder .Could you provide coding ......

    Thanks in Advance

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    Attachments with java mail, use the MimeMultipart as a container inside the usual Message

    See: jGuru: Fundamentals of the JavaMail API

    (code from that page, in case you can't see the url yet)
    Java Code:
    // Define message
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, 
      new InternetAddress(to));
    message.setSubject("Hello JavaMail Attachment");
    
    // Create the message part 
    BodyPart messageBodyPart = new MimeBodyPart();
    
    // Fill the message
    messageBodyPart.setText("Pardon Ideas");
    
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    
    // Part two is attachment
    messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(filename);
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(filename);
    multipart.addBodyPart(messageBodyPart);
    
    // Put parts in message
    message.setContent(multipart);
    
    // Send the message
    Transport.send(message);
    Last edited by travishein; 11-12-2009 at 08:17 PM.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by balaji csc View Post
    Hi,
    Could you please help me........
    I want to send attached Excel file through Java Mail. For Example My Excel file is located in c:\\testing folder .Could you provide coding ......

    Thanks in Advance
    You should show your effort lol. ;)

    Anyway, as travishein mentioned in his post, Java Mail API contains all you need. Did you able to find the document and read?

    JavaMail API

Similar Threads

  1. Java Mail sending
    By jazz2k8 in forum Advanced Java
    Replies: 1
    Last Post: 05-01-2011, 06:08 AM
  2. Replies: 5
    Last Post: 08-02-2008, 08:05 PM
  3. Sending a Mail
    By haiforhussain in forum Advanced Java
    Replies: 7
    Last Post: 07-30-2008, 12:28 AM
  4. Sending Mail Using Sockets
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:05 PM
  5. Sending a mail with the local mail program
    By thedude in forum Advanced Java
    Replies: 2
    Last Post: 07-23-2007, 12:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •