Sending attachments with emails in Javamail

I'm trying to send attachments with emails using Javamail. Following is the code through which I'm trying to achieve that. It works as expected on a JRE1.6 environment. But on JRE1.5, the content of the file gets added to the mail body as text.I want the file to be sent as an attachment.
Any pointers on the observed difference in behavior would be highly appreciated!
String msgText = mailInfo.getMessage();
        String attachmentFileName = mailInfo.getFileName();
        MimeBodyPart mimeBodyPart = new MimeBodyPart();
        mimeBodyPart.setText(msgText);
        // create the second message part
        MimeBodyPart attachmentBodyPart = new MimeBodyPart();
        // attach the file to the message
        FileDataSource fileDataSource = new FileDataSource(attachmentFileName);
        attachmentBodyPart.setFileName(fileDataSource.getName());
        attachmentBodyPart.setDataHandler(new DataHandler(fileDataSource));
        // create the Multipart and add its parts to it
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(mimeBodyPart);
        multipart.addBodyPart(attachmentBodyPart);
        message.setContent(multipart);The email in case of JRE1.5 is as follows
{color:#0000ff}------=_Part_0_33189144.1233078680250
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi...Test Mail
------=_Part_0_33189144.1233078680250
Content-Type: application/octet-stream; name=corba_architecture.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=corba_architecture.pdf
Content-ID: Attachment
JVBERi0xLjIgDSXi48/TDQogDTggMCBvYmoNPDwNL0xlbmd0aCA5IDAgUg0vRmlsdGVyIC9GbGF0
ZURlY29kZSANPj4Nc3RyZWFtDQpIiUWPW07DMBBFV+A93E9QlWBP/Kj5awt8USFRbyBKnTQIkshK
YfvYcQoaybrSzDkzFhCxQgemeWkUyKTXEIeSHMGjZXvHSFBJCpXUpQLcE+NIlbCHFw4pUxeuZQUv
ueY25gYxk9mKmH9wtwvNpZ99M1+jc2wxXzxweHvf73AP9xGFhaIsTyC3/w6ZDYfxaxoHP8w4jmf/
------=_Part_0_33189144.1233078680250-- {color}

Following is the debug trace obtained on running the program on 1.5.
+12:45:57,218 INFO [MailerThread] EmailManager:306 - Sending message {toAddress [email protected],+
+replyTo =null,+
+cc =null,+
+message =Hi...Test Mail,+
+subject =test mail,+
+contentType =null fileName =C:\docs\cbe\dist computing\A.txt }+
Loading javamail.default.providers from jar:file:/C:/docs/cbe/lib/mail-1.4.jar!/META-INF/javamail.default.providers
DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=imaps, className=com.sun.mail.imap.IMAPSSLStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtps, className=com.sun.mail.smtp.SMTPSSLTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3s, className=com.sun.mail.pop3.POP3SSLStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: getProvider() returning provider protocol=smtp; type=javax.mail.Provider$Type@77eaf8; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "10.16.68.131", port 25, isSSL false
+220 mailhost5.vmware.com ESMTP Postfix (mailhost5)+
DEBUG SMTP: connected to host "10.16.68.131", port: 25
EHLO sbanerjee
+250-mailhost5.vmware.com+
+250-PIPELINING+
+250-SIZE 26800000+
+250-VRFY+
+250-ETRN+
+250-ENHANCEDSTATUSCODES+
+250-8BITMIME+
+250 DSN+
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "26800000"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
+250 2.1.0 Ok+
RCPT TO:<[email protected]>
+250 2.1.5 Ok+
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   [email protected]
DATA
+354 End data with <CR><LF>.<CR><LF>+
------=_Part_0_3278348.1233126957281
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi...Test Mail
------=_Part_0_3278348.1233126957281
Content-Type: text/plain; charset=us-ascii; name=A.txt
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=A.txt
Content-ID: Attachment
adasdasdd
------=_Part_0_3278348.1233126957281--
+.+
+250 2.0.0 Ok: queued as 5BE5BDC100+
+12:45:59,125 INFO [MailerThread] EmailManager:331 - Message {toAddress [email protected],+
+replyTo =null,+
+cc =null,+
+message =Hi...Test Mail,+
+subject =test mail,+
+contentType =null fileName =C:\docs\cbe\dist computing\A.txt } sent to the SMTP server successfully+

Similar Messages

  • Can not send attachments with emails on Me and aol Imap??

    I have an aol and MobileMe imap accounts set up with my mac mail, but I can not send any email with attachemnts no matter how small the smallest I have tried is 152Kb. I have been reeding the threads about not being able to send any email, but I can send and recive emails(with attachments) just not send with attachments.I have been able to send attachments with my aol Imap account before.
    I have recently signed up to Mobile me and created the Me Imap account, this is the first time I have had to send an attachment. Is it something to do with the Mobile me?? Any help much appreciated
    still relitivly new to Mac....

    Hi Kursten, and a warm welcome to the forums!
    Have you tried Port 587 instead of 25 for the .me account anyway?
    Mail>Preferences>Accounts>Outgoing SMTP>Server Settings...

  • Why can I not send attachments with emails?

    Since updating to Maverick have been unable to send attachments to emails. WHY?

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left. If you don't see that menu, select
    View ▹ Show Log List
    from the menu bar.
    Click the Clear Display icon in the toolbar. Then try the action that you're having trouble with again. Select any messages that appear in the Console window. Copy them to the Clipboard by pressing the key combination command-C. Paste into a reply to this message (command-V).
    When posting a log extract, be selective. In most cases, a few dozen lines are more than enough.
    Please do not indiscriminately dump thousands of lines from the log into this discussion.
    Important: Some private information, such as your name, may appear in the log. Anonymize before posting.

  • Sending attachments with email from iPad

    Can I send attachments, such as a pages file, when I send an email from my iPad?
    Thanks for your help

    If you want to send photos, you can do it two ways:
    1. From Photos, tap the rectangle with the curved arrow, then tap the photos you want to send, then tap the Share button to create a new mail message.
    2. From an already created mail message, do a copy-paste from Photos to include photos in the mail message.
    Other apps are a little different. You can always copy-paste but that may get cumbersome.

  • Send attachments with Email in WebDynpro[Java]

    Hi All,
    Developing a webdynpro application in Java Which will  sending -mail.Is it Possible to send attachments[Ex: Excel/doc Files] in webdynpro ?How to do it ?Please Help me out..
    Regards,
    Ramganesh.

    Hi,
    Try this code;
    Properties properties = new Properties();
         properties.put( "mail.smtp.host", <>);
         Session session = Session.getInstance( properties, null);
         MimeMessage message = new MimeMessage( session);
         try
              MimeMultipart multipart = new MimeMultipart();
              BodyPart messageBodypart = new MimeBodyPart();
              message.setFrom( new InternetAddress( <sender mail id>));
              message.setRecipient( Message.RecipientType.TO, new InternetAddress( wdContext.currentContextElement().getP_Email_Id()));
              message.setSubject( "Subject");
              messageBodypart.setText( "Text");
              multipart.addBodyPart( messageBodypart);
              messageBodypart = new MimeBodyPart();
              messageBodypart.setDataHandler( new DataHandler( new FileDataSource( <Path of file>)));
              messageBodypart.setFileName( new FileDataSource( <Path of file>).getName());
              messageBodypart.setHeader( "Content-Type", "application/pdf");
              multipart.addBodyPart( messageBodypart);
              message.setContent( multipart);
              Transport.send( message);
         } catch (AddressException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
         } catch (MessagingException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
    Regards
        Vinod V

  • Sending attachments with emails

    Hi,
    Can anyone tell me/show me how to send an attachment that is uploaded from the client?
    Thank you.

    Hi,
    Can anyone tell me/show me how to send an attachment that is uploaded from the client?
    Thank you.

  • Attachments with emails are a PROBLEM!

    Boy...I just dread having to send attachments with emails. Even a simple, one page flyer in pdf form! I have high speed internet connection - but no matter what size the attachment the emails just won't send. They repeatedly time out and/or have the drop down menu pop up to select another server (have three different email addresses/servers). No matter what server I use the emails will sit in the "outbox" all day and sometimes more than one day before they actually get sent. Does this happen to anyone else? Ideas to fix? THANKS!!

    I am referring to new email messages, generated by me - sending to a recipient - that include attachments (usually pdf's) from my MacBook Pro. It is quite frustrating.... Thanks for your interest in helping me with this!

  • How do I send attachments by email from my iPad

    How do I send attachments by email from my iPad

    The thing to remember is that iOS email attachments start with the document itself, not from the Mail app.
    1. Select the thing you want to send in an app that handles it, (for example a Photo might be sent from Photos, a PDF from GoodReader etc.)
    2. Then tap the "share" button (which I see others have kindly posted screenshots for) and create an email containing that attachment.
    Peter
    <Link Edited By Host>

  • Attachments with email submission receipt?

    Based on response to check boxes, I would like to send an attachment with email submission receipt. The attached file would be condistional. For example, with response A, the submitter would get the attachment docA.pdf, with response B, the submitter would get the attachment docB.pdf, etc.
    Is this possible? Thank you.

    Sorry this is not possible. We don not support sending attachments with the email receipts. Also, you can't even have conditional email body message.
    Gen

  • Sending attachments with Netzero as SMTP server

    Since upgrading to Leopard last November, I have been unable to send emails with attachments. Email is received, with or without attachments, with no problem. Text emails can be sent with no problems. Netzero is the ISP, and is set as the outgoing SMTP server. Attachments were no problem with Tiger. I have also tried using gmail as the outgoing SMTP server, to no avail. I installed Thunderbird, and have the same result. I've contacted Netzero, and cannot get a definite response. I have also tried using the Mac dial-up software to by-pass Netzero but am able to send or receive with Mail.
    Is anyone able to send attachments to emails while using Netzero as the SMTP server? If so, I'd certainly appreciate advise, and I'd know that it's my problem somewhere. Thanks!

    Sammie - I have not been able to solve this frustrating problem
    yet....I have exchanged emails with Netzero, and they say the are
    "working on the problem". I have also posted information as feedback
    to Apple, at http://www.apple.com/feedback, which you may wish to do
    also.
    I have two work-arounds, as you may have seen in some of my posts at
    the discussion forums. If you haven't seen them, they are:
    First, you can use a webmail service...for instance, you can compose
    mail from your NetZero account (or gmail, for example), and upload
    your attachments before sending. This is slow, but works. Secondly, you can
    make a new, small (e.g., 25GB) partition on your Leopard disk, and
    install Tiger on that partition. I then drag and drop attachments
    into this partition from my Leopard disk, then restart on the Tiger
    disk. I am then able to use the Tiger Mail application to compose and send the
    message for me. This is cumbersome, but it does work, and I don't have to change providers.
    I'm glad to see that were not alone, though! Please let me know if you are able to figure this out...I'll keep you posted as well. Bill

  • How do I send attachments in email as an icon

    How do I send attachments in email as an icon

    I mean when I have dropped a photo into the email how do I then change that to an icon so that other non Mac users can see it easier

  • I can't send attachments with Thunderbird?

    I can't send attachments with Thunderbird. I can write a message but when I click on Attach, I get the message "Thunderbird has stopped working. A problem has caused the program to stop working correctly. Windows will close the program and notify you if a solution is available." There is only a "CLOSE PROGRAM" button displayed and when I click on it Thunderbird stops running. I'm not sure whether this is a Thunderbird problem or a Windows 7 problem. Any ideas on what is causing this and how to fix it?

    Try to start Thunderbird in safe mode.
    https://support.mozilla.org/en-US/kb/safe-mode

  • IPhone does not forward attachments with emails

    My iPhone does not forward attachments with emails.

    Make sure you open the email and fully download the attachments before trying to forward them.  Large attachments are often only partially downloaded unless you tap the option to fully download the.

  • Send table with email as excel-attachment

    Hi.
    I have such a requirement. I have a report that selects data and show it in ALV form.
    No I need to execute it as background job and then send emails with selected data as an attached excel file.
    Does anybody know the way to convert usual internal table into the internal table that contains the same data in a excel file form, that I could send then with email?
    All ways of converting itab to excel use excel file on frontend PC as a destination. Is there any way to avoid downloading to a real file and then uploading back to internal table?
    Thanks in advance.

    hi,
    these steps will help u to achieve your requirement.
    step 1 : for getting the selected records only , u can use the below code
                    lr_selections = go_alv_table_ref->get_selections( ).
                    lr_selection(gs->get_selected_rows( RECEIVING value = gt_rows ).
    Step2 : paa the selected records (gt_rows) to the method cl_bcs_convert=>string_to_solix - (give the code page as 4103 -this wll convert to an excel file ) get the file and send as a mail attachment using the method 'add_attachement' from the class 'cl_document_bcs'.
    Hope this helps,
    Thanks,
    Sindhuja

  • Sending Attachments with JavaMail API

    I have an application where I need to develop a simple e-mail servlet where, from an HTML form, clients can enter their return email address and attach a file and send it to me. The jGuru short course said that when trying to send attachments via a servlet, the user must upload the attachment with the encoding type "multipart/form-data". If I remove the "enctype=multipart/form-data" statement, I can successfully send an email without an attachment. But when I add the statement, the servlet fails. Here is the HTML that I have been using, without success:
    <form enctype="multipart/form-data" action="../servlets/TestEmail" method="post">
    From: <input type="text" name="from" value=""><br>
    Subject: <input type="text" name="subject" value=""><br>
    File to Attach: <input type="file" name="filename"><br>
    Message: <textarea name="message"></textarea><br><br>
    <input type="submit" value="Send">
    </form>
    Can anyone show me the error of my ways?
    Many thanks.
    Chris

    Hi,
    You'll need to use the servlet attachment jar from http://www.servlet.com in your webserver library. Check out the site, it'll tell you what to do.
    I've also done an example servlet at http://www.salniere.com/WebTests/ServletMail which you can download and check out.
    good luck
    Kevin

Maybe you are looking for

  • Problem: Firefox + Office 365 + PDF

    Hi, I seem to have found a tricky problem with Firefox 23.0.1, Office 365, and PDF. After multiple trials, the problem occurs only when I try to attach a PDF to an email (using Office 365) while using Firefox. After attaching the file to the email, t

  • DPS video folio overlays not working as prompted

    Hi All, Some of the video folio overlays I have selected are not working within my folio, even though they are selected. The video is not stopping on last frame and is allowing the pause function even though I have checked the box to disabled it. It

  • Using iPhoto on External, but photos are mysteriously being loaded internal

    I just recently moved my iPhoto library to my external hard drive. It works fine there. I deleted the library on my MacBook Pro. However, when I upload photos from my camera, it shows both the external hard drive's memory and the laptop's memory bein

  • Oracle CASE WHEN Bug

    Hi! During my work, i found an interesting bug like thing with the CASE WHEN condition. The following query gives back 1 (as a correct result) for w.val if the "case when..." line is commented. It gives null if the case when line is left in the query

  • Referring to images from portal theme attributes

    In our branded and customized theme we have a problem. Some background images are not displayed. The properties are set as displayed at the end of this message, I am not familiar with this type of value. The background image is White, and then an url