PDF File corrupted when being sent by email by tomcat... what's wrong?

Hi,
I have been a little frustrated trying tomcat to send a pdf file by email after it have been uploaded to the server.
First case:
If i run the same code in windows, it works.
Second case:
If i run the same code manually in java in the tomcat linux server it works.
Third case:
The problem is when the code is running by tomcat in a jsp page.
In every situation the email goes to the sender, but in the last one, the reported size of the pdf file is not the same as the first and second case resulting in a pdf corruption. It cannot be opened.
I am running Tomcat 5.5.17 with jdk 1.5.0.10 in a Redhat Enterprise Linux 4 Server.
This is the code called by a jsp page.
package eor;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class SendMailUsingAuthentication {
private static final String SMTP_AUTH_USER = "user";
private static final String SMTP_AUTH_PWD = "pass";
public void sendEmail() {
String from = "[email protected]";
String to = "[email protected]";
String subject = "Sendit from linux ";
String bodyText = "This is a important message with attachment";
String filename = "//home//test//HON-SOLMANT28AGO08.pdf";
Properties properties = new Properties();
properties.put("mail.smtp.host", "Testmailhost");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "25");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(properties, auth);
session.setDebug(true);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
message.setSentDate(new Date());
// Set the email message text.
MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setText(bodyText);
// Set the email attachment file
MimeBodyPart attachmentPart = new MimeBodyPart();
FileDataSource fileDataSource = new FileDataSource(filename) {
@Override
public String getContentType() {
return "application/octet-stream";
attachmentPart.setDataHandler(new DataHandler(fileDataSource));
attachmentPart.setFileName(filename);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messagePart);
multipart.addBodyPart(attachmentPart);
message.setContent(multipart);
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
private class SMTPAuthenticator extends javax.mail.Authenticator {
@Override
public PasswordAuthentication getPasswordAuthentication() {
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
}I will appreciate your help to solve this situation.
Regards,

bshannon wrote:
Are you sure you're using the Sun implementation of JavaMail on RedHat? Some versions of
Linux come with the Gnu version of JavaMail included, which might behave differently.
If you turn on session debugging, what does the protocol trace show?
Are you sure you're sending the same file in all cases?
Are you sure the file upload is complete before you send the file?Are you sure you're using the Sun implementation of JavaMail on RedHat?
Yes I am using JavaMail 1.4 from SUN.
If you turn on session debugging, what does the protocol trace show?
Yes. Below you will find the protocol trace.
Are you sure you're sending the same file in all cases?
Yes I am sure.
Are you sure the file upload is complete before you send the file?
Good point. I will check it out!
Protocol Trace output:
Grabando archivo en disco...
DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "168.243.220.232", port 25, isSSL false
220 SMTP IM2 Proxy Server Ready
DEBUG SMTP: connected to host "168.243.220.232", port: 25
EHLO web2.enteoperador.org
250-ESMTP Server Ready
250-SIZE 0
250-DSN
250-AUTH LOGIN
250-AUTH=LOGIN
250-STARTTLS
250 TLS
DEBUG SMTP: Found extension "SIZE", arg "0"
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "TLS", arg ""
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
c3ZhbGxl
334 UGFzc3dvcmQ6
dmFsZXJpYW1pYW1vcg==
235 Authenticated successfully
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
250 +OK Sender OK
RCPT TO:<[email protected]>
250 +OK Recipient OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   [email protected]
DATA
354 Start mail input, end with "<CR><LF>.<CR><LF>"
Date: Fri, 26 Sep 2008 17:47:18 -0600 (CST)
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: Sendit from linux
MIME-Version: 1.0
Content-Type: multipart/mixed;
        boundary="----=_Part_0_28970806.1222472838992"
------=_Part_0_28970806.1222472838992
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
This is a important message with attachment
------=_Part_0_28970806.1222472838992
Content-Type: application/octet-stream;
        name="//www//tomcat//upload//oper-hon//HON-SOLMANT28AGO08.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
        filename="//www//tomcat//upload//oper-hon//HON-SOLMANT28AGO08.pdf"
JVBERi0xLjANCg0KMSAwIG9iag0KPDwgL1R5cGUgL0NhdGFsb2cgL1BhZ2VzIDIgMCBSID4+DQpl
bmRvYmoNCg0KMiAwIG9iag0KPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFsgMyAwIFIgXSAvQ291bnQg
MSA+Pg0KZW5kb2JqDQoNCjMgMCBvYmoNCjw8IC9UeXBlIC9QYWdlIC9QYXJlbnQgMiAwIFIgL01l
77+9DC/vv73vv71YYO+/vVsMF20t77+977+9Nkg777+9bitg77+9KO+/ve+/ve+/ve+/ve+/vXw1
X++/vW8J77+977+9NQknfu+/vQgw77+9TX1177+9YSwS77+9
------=_Part_0_28970806.1222472838992--
250 +OK message queued for delivery.
QUIT
221 Service closing transmission channel closing connection

Similar Messages

  • HT3697 I am trying to convert a Keynote Presentation to a cross platform PDF file. When using export it creates a 30mb file when it only need to be 2-3mb and so cant email or use it very easily. How do I get the file size down?

    I'm trying export a Keynote presentation to PDF, or other format, to use on Windows PC, iPad and other devices.
    The file Keynote create is way too large at 30mb+. So cant email or share it very easily
    If I print it and to Adobe PDF I can get it to 3mb, but have to crop it manually, and some settings or graphics are not so good or accdeptable!
    Does anyone know how to do this?

    Use Dropbox to send large files that cant be sent using email:
    https://www.dropbox.com/

  • Why can't I open/see PDF files that are embedded in an email or sent through the internet?

    I can read/see PDF files that are attached to an email, but I can't see/read them if they are embedded in an email or sent through the internet.

    I have a similar problem. I can open, read, and save PDF files, but I can't view my online bank statement on my Mac. The statement opens automatically if I use a PC, but on my Mac the page says I need Adobe Reader to view my statement. I already have the latest version of Adobe Reader. The problem seems to be that that the plugin only goes to the Libray. It doesn't get installed into Safari or into FireFox either.

  • I opened a PDFs file that was attached to an email message and now it will not close when I press "Done" as it usually does. Does anyone have a solution to suggest? Thanks.

    I opened a pdf file that was attached to an email message I received and now it will not close when I press "Done" as files usually do. Does anyone have a solution to suggest please? Thanks.

    Try double clicking your home button then force close the stuck PDF by swiping upward. Once you've done that just click the home button again to exit.

  • How can I embed a pdf file into the body of an email?

    How can I embed a pdf file into the body of an email?

    The problem is defining what it even means to “embed” a PDF file in the body of an e-mail, especially if you are dealing with a multiple page PDF file.
    E-mail is either pure text, rich text (something akin to RTF in Word), or HTML. PDF is not compatible with any of these. Thus, to embed a PDF file, something has to be converted and that means the PDF would be converted to a less graphically rich raster format. But is that what you would really want?
    I think that the MacOS and iOS e-mail clients do under some circumstances place an attached PDF file within HTML segments and by clicking on same, you get the equivalent of extracting the full PDF file, but I have no real experience with that.
    Another alternative is HTML with a proxy image with a hyperlink to an external PDF file that is invoked when you click on the hyperlink.
    Perhaps you can explain what you are really trying to accomplish and what the recipient of such an e-mail's actual experience would be?
              - Dov

  • Files corrupt when saved as Jpeg.

    Recently I have been creating invitations in illustrator but when I save them as a JPEG file it says file corrupted when I try to upload them for printing. How can I fix this without creating an entirely new invitation?

    Why are you saving as jpeg for print out of Illustrator? Work in CMYK and save as pdf.
    Working in CMYK means that, provided your monitor is calibrated correctly, what you see is what you get.
    You may be in for an unpleasant surprise if you work in those nice, bright RGB colours and they come out all dull and muddy when printed.
    Pdf means that vector art remains as vector art. It is bad Latin to pixellate things when you don’t need to.

  • Why are my messages being sent through email rather than iMessage?

    Why are my messages being sent as email rather than iMessage?

    Not being sent as email - shown as being sent from an email address because you have selected to start new iMessage conversations from your Apple ID email address on your iPhone.
    When registering an iPhone with iMessage, the phone number along with your Apple ID email address is registered with it.
    Go to Settings > Messages > Send & Receive > Start New Conversations From - select your iPhone's phone number.

  • Need Help ASAP  my State tax form is in a PDF file and the attachment in my email says Please wait

    Need Help ASAP  my State tax form is in a PDF file and the attachment in my email says Please wait...
    I tried downloading updates like it said to but it still will not display the document.  How do I print the PDF file ASAP

    Can you give us a LOT more info?
    What email client? What version of Reader (I can only assume you even have Reader at this point)?
    Please wait? I'm sure it says more than that, right?
    Have you tried simply saving the PDF (it IS a PDF correct?) to your desktop and opening it from there?
    Did you get this form from the IRS or did it come from somewhere else? If the IRS again, what version of Reader?
    Help us help you.

  • We used to get a 'whooshing' noise when we sent an eMail using mac Mail. This no longer happens. We recently updated to Mountain Lion 10.8.1  Can anyone throw light  on this please?    David

    We used to get a 'whooshing' noise when we sent an eMail using mac Mail. This no longer happens. We recently updated to Mountain Lion 10.8.1  Can anyone throw light  on this please?    David

    Hi
    I am sorry to see you are having problems with your BT Service
    I suggest you contact the forum mods they should be able to get this problem sorted for you this is a link to them http://bt.custhelp.com/app/contact_email/c/4951
    They normally reply by email or phone directly to you within 3 working days they will take personal ownership of your problem until resolved and will keep you informed of progress
    They are a UK based BT specialist team who have a good record at getting problems solved
    This is a customer to customer self help forum the only BT presence here are the forum moderators
    If you want to say thanks for a helpful answer,please click on the Ratings star on the left-hand side If the reply answers your question then please mark as ’Mark as Accepted Solution’

  • I used to use the free version of Adobe Reader to convert my publisher files to pdf files. When I was making a booklet for our hockey team, it said I had to buy it. Now I bought it and it won't convert the files. I am ready to throw this computer out the

    I used to use the free version of Adobe Reader to convert my publisher files to pdf files. When I was making a booklet for our hockey team, it said I had to buy it. Now I bought it and it won't convert the files. I am ready to throw this computer out the window!! Can you tell me what is the problem? No it does not exceed 100 M. either.

    Adobe Reader never converted Publisher files to PDF, for free, never. I suspect you use to have the (paid for) Adobe Acrobat. Sometimes people have Acrobat (more than $300 worth) and install Adobe Reader over the top, losing that valuable software.
    That said, if you subscribed to PDF Pack it should do this conversion. What exactly happens now.

  • Why can't I save text I've entered into a PDF file?  When I hit "Save As", only the PDF document is saved, but not the text i typed into the document.  I'm using Windows 8.

    Why can't I save text I've entered into a PDF file?  When I hit "Save As", only the PDF document is saved, but not the text i typed into the document.  I'm using Windows 8.

    THANK YOU!
    Jan Whitfield
    The College Planning Center
    250 Palladio Parkway, Suite 1311
    Folsom, CA 95630
    (916) 985-0453
    www.TheCollegePlanningCenter.com

  • I've been attaching pdf's to emails forever.  All of the sudden my pdf files won't attach to any email.  I have tried from home, work, different providers, etc.  Nothing is working.  What could the problem be?

    I have been attaching pdf files to emails forever.  All of the sudden my pdf files won't attach to an email.  It just sits there and spins like it's trying to attach but quits half way through.  What could the problem be?

    Please try repairing Reader installation on your machine. Do you get any error message while attaching the pdf file?
    Regards,
    Deepak

  • Forgot apple id security question answers - reset email is not being sent to email addresses

    forgot apple id security question answers - reset email is not being sent to email addresses

    Hi there,
    Why dont you just change your Apple ID (your email)? Make a new Apple ID and do the security questions that you will remember. Also, make sure you write down all the info with your Apple ID for later refrence.
    To create a new Apple ID, follow the easy steps below:
    Settings > Itunes and App stores > Tap "Apple ID: (YOUR APPLE ID IS HERE!)" > Tap "Sign Out" > Tap "Create New Aple ID"

  • Hi! I've just downloaded my PDF file but when I open it with adobe reader for iPhone, the toolbar do

    Hi! I've just downloaded my PDF file but when I open it with adobe reader for iPhone, the toolbar doesn't show! Can please anybody tell me why?

    Hi Elena, you have to tap on screen of iPhone, toolbar will just slide in.
    -Charu

  • Movie file corrupts when added

    I have been adding different movies successfully to the menu on iDVD, but one file corrupts when added. The file will open and play outside of iDVD with no problems. Any suggestions?

    Hi
    iMovie and iDVD are very picky on what they can or can not use for VIDEO CODECS !
    To find out what a specific video file has for CODEC
    - open it with QuickTime player (can open so so many more)
    - press cmd+I (turns on inspector)
    - read - video formatted as: nnnnnnnnnnnnnn
    and frames per second: YY.yy
    What does they say ?
    Yours Bengt W

Maybe you are looking for

  • Having trouble installing itunes, keep getting error message R6034

    I'm trying to install i-tunes and I keep getting a runtime errorr message and a windows message. Does anyone have suggestions on how I can re-install i-tunes?

  • Can't Distribute Forms - Acrobat Standard 9.5.5

    We have recently upgraded our last XP user to a new computer with Windows 7 Pro SP1. She uses Acrobat to create forms for our customers to fill out. Using Acrobat 9 to distribute forms on XP for a few years no problem. On Win 7, when we go to distrib

  • Purpose of Goods Issue function in Delivery

    Hai Guys,    Do help me out in getting informations about the    following. purpose of Goods Issue function in Delivery  and list out all the activities which happens automatically in R/3 due to goods issue operation. detailed answers or links for th

  • Update 10.3.1.1779

    I have found one notification regarding an update to 10.3.1.1779. my question is what is new in this update and is it really necessary in my Q5. is it safe to down over wifi to my phone. I am using Indian version of BB Q5. Pls repry soon.

  • Question about Lightroom 5 licence

    Hi Everyone I'm trying the Creative Cloud Photography plan (one-year) I have a only one question ( at the moment) If I decided to cancel my subscription after one year, what about the licence ? If I want to stay with that  version in my computer , do