Error when trying to send an attachment

Hi there,
I am running an application in Tomcat 5.5 and I am trying to send an email with an attachment via java mail. The attachment will eventually be a zip file containing wav files but I can't seem to get it to work with a text file yet.
I may be a little confused...I am especially confused with the DataHandlerSet stuff.
Here is the code:
public String sendmail(String msgSubject)
     //Sets some variables.
    String emailmultipart = "true"; //if this is set to false sends a simple message.
    String msgText = "Some text \n\n";
    String smtphost = "myhost";
    String emailto = "[email protected]";
    String emailfrom =  "[email protected]";
    //Gives the path of where the sound files are.
    File soundfile = new File("myfile.txt");
    boolean debug = true; // change to get more information
    String msgText2 = "multipart message";
    boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
       // set the host
    Properties props = new Properties();
    props.put("mail.smtp.host", smtphost);
      // create some properties and get the default Session
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(debug);
    try
          // create a message
           Message msg = new MimeMessage(session);
           // set the from address
           InternetAddress from = new InternetAddress(emailfrom);
           msg.setFrom(from);
           //set the to address
           InternetAddress[] address =
               new InternetAddress(emailto)
           msg.setRecipients(Message.RecipientType.TO, address);
           //set subject - support request id
           msg.setSubject(msgSubject);
          //decides whether to send plain text message or multi text message (from true/false in the command line)
          //sends a simple plain text email
          if(!sendmultipart)
             // send a plain text message
             msg.setContent(soundfile, "text/plain");
          //sends an attached file.
          else
             // send a multipart message// create and fill the first message part
             MimeBodyPart mbp1 = new MimeBodyPart();
             //adds the text as normal
             mbp1.setContent(msgText, "text/plain");
             // create and fill the second message part
            MimeBodyPart mbp3 = new MimeBodyPart();
            // attach the file to the message
              //FileDataSource fds = new FileDataSource(filen);
              FileDataSource fds = new FileDataSource(soundfile);
             mbp3.setDataHandler(new DataHandler(fds));
             mbp3.setFileName(fds.getName());
//             mbp3.setContent();
            Multipart mp = new MimeMultipart();
            //adds the text to the message
            mp.addBodyPart(mbp1);
              //adds the attachment to the message
              mp.addBodyPart(mbp3);
            // adds the content to the message
            msg.setContent(mp);
         //Transport - sends the message.
         Transport.send(msg);
    catch(MessagingException mex)
      mex.printStackTrace();
    //log.debug("At end of Send email");
    return "nothing";
}Here is the error:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
     java.io.IOException: "text/html" DataContentHandler requires String object, was given object of type class javax.mail.internet.MimeMultipart
     at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:566)
     at javax.mail.Transport.send0(Transport.java:151)
     at javax.mail.Transport.send(Transport.java:80)
     at questionnaireweb.Formemail.sendmail(Formemail.java:337)
     at org.apache.jsp.web.emailrecorded_jsp._jspService(org.apache.jsp.web.emailrecorded_jsp:338)
     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:731)
     at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
     at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
     at java.lang.Thread.run(Thread.java:595)
I'd be really grateful for any help. I can't seem to get past this error not matter what I try. Sending the simple mail works, but sending an attachment produces the error above. I have seen similar errors before but when the user actually wants to send html and not a file.
Thanks a lot,
Jess

HI ,Thanks for your response. That was an error in the code I posted, but wasn't the error I was trying to solve. Once correcting that error you pointed out I am getting the problems not when I send a plain text email like:
          if(!sendmultipart)
             // send a plain text message
             msg.setContent(msgText, "text/plain");
          }but when I try and send multipart messages doing this:
          else
             // send a multipart message// create and fill the first message part
                   MimeBodyPart mbp1 = new MimeBodyPart();
     mbp1.setText(msgText);
      // create and fill the second message part
     MimeBodyPart mbp3 = new MimeBodyPart();
     // attach the file to the message
     FileDataSource fds = new FileDataSource(soundfile);
     mbp3.setDataHandler(new DataHandler(fds));
     mbp3.setFileName(fds.getName());
                   Multipart mp = new MimeMultipart();
     //adds the text to the message
      mp.addBodyPart(mbp1);
      //adds the attachment to the message
      mp.addBodyPart(mbp3);
       // adds the content to the message
      msg.setContent(mp);
     }So i get the error when executing the else branch.
Can you spot any errors here? I get the same error as mentioned earlier.
Thanks a lot,
Jess

Similar Messages

  • Error when trying to send questionnaire (SURVEY)

    Hi All
    I have designed and built a questionnaire using the SURVEY transation in BIW. I am now testing the send to function but I am unable to send this to users as the following error occurs;
    You have recieved a status for the following doc:
         Encues.
    Sent:
         14.05.2007 10:16:28
    Sent By:
         Christopher John Burleigh
    Status for destination [email protected]:
        Internal Error: CL_SMTP_RESPONSE error code ESMTP unknown 554 554 <[email protected]>: Sender address rejected.
    I have think the SCOT transaction where SMTP email con be configured may help but after trying I can't see how.
    Please Help!!!
    Thanks in advance
    Chris

    HI ,Thanks for your response. That was an error in the code I posted, but wasn't the error I was trying to solve. Once correcting that error you pointed out I am getting the problems not when I send a plain text email like:
              if(!sendmultipart)
                 // send a plain text message
                 msg.setContent(msgText, "text/plain");
              }but when I try and send multipart messages doing this:
              else
                 // send a multipart message// create and fill the first message part
                       MimeBodyPart mbp1 = new MimeBodyPart();
         mbp1.setText(msgText);
          // create and fill the second message part
         MimeBodyPart mbp3 = new MimeBodyPart();
         // attach the file to the message
         FileDataSource fds = new FileDataSource(soundfile);
         mbp3.setDataHandler(new DataHandler(fds));
         mbp3.setFileName(fds.getName());
                       Multipart mp = new MimeMultipart();
         //adds the text to the message
          mp.addBodyPart(mbp1);
          //adds the attachment to the message
          mp.addBodyPart(mbp3);
           // adds the content to the message
          msg.setContent(mp);
         }So i get the error when executing the else branch.
    Can you spot any errors here? I get the same error as mentioned earlier.
    Thanks a lot,
    Jess

  • FTP error when trying to send crystal report to FTP destination

    Hello experts.
    I am trying to send a crystal report to a FTP destination. I have enabled the FTP destination on all servers that have a destination option. I am able to connect to the FTP site manually from the server that is running crystal reports server. However every time I try to run the report in CMC, it fails with the following message:
    Error Message: connection error. CrystalEnterprise.Ftp: WSA11004
    Any ideas on what this message means and how to fix the issue?

    Here's the details of the Note
    Symptom:
    Scheduling of the Crystal Report to FTP destination prompts the Error: Connection error, CrystalEnterprise.Ftp: WSA0.
    Cause:
    Every time when Crystal Report is scheduled to FTP destination, a connection is made to FTP server from server where job server is installed. If there is limitation on connection being made to FTP server then this error occurs.
    Resolution:
    For FTP sites in IIS:
    - Open IIS Manager
    - Go to Properties
    - Click on the FTP site tab
    - In FTP site connections, check for Connection limited to :
    - When report is long running do check how much time it takes to complete scheduling. - Accordingly change the connection time out setting in Properties of FTP site.
    - For FTP sites created using FTP Server applications, setting for Connection limited to and connection timeout will remain same.

  • HELP....why do I keep getting "Not Delivered" errors when trying to send a Group MMS text message?

    I am trying to send a Group MMS text. There are 6 recipients. I hit "send" and the progress bar goes almost to the very end, and then hangs up....and eventually I get a "Not Delivered" error message. I click on the "i" icon and it says "your message was not sent. Tap try again to send this message." I've done that time and time again, and the same thing happens. What am I doing wrong?

    Try sending it as a regular text message... turn off iMessage.

  • ME23N Error when trying to send PO via IDOCS to another system?

    Hello Experts,
    I am getting wired message what I ma trying to send PO via IDocs to other SAP system (XI)
    I went to all partner , port configurations on WE20 and everything there seems to be fine but once I go to ME23N, then GO TO -> MESSAGES , than opens another windows when you key in MESSAGE CONTROL DATA that have been mantained
    in the outbound parameters in the PARTNER PROFILE configurations.Then I am getting the message :
    'No communication data has been defined for transmission medium 6'-----
    The LED on "PO:output screen' is YELLOW and never gets green.
    Can someone tell me how to overcome this and send my  PO Idocs?Please some more details will be appreciate it!
    Thank you much  eveyone!
    Boby<b></b>

    I just got the same problem. Everything worked fine when i was using message type ORDERS01, but when i changed it to ORDERS05 this problem started happening.
    This might solve your problem. If you have it solved out can you tell us the solution you found??
    regards,
    Diogo

  • Mail crashes when trying to send an attachament

    Since using Snow Leopard I have had endless trouble with Mail quitting just after trying to send an email with an attachment. In the end most of them go after several attempts but with the last one (only 450K) I had to resort to using Entourage and even that crashed twice before sending the attachment. I have upgraded to 10.6.1 but that makes no difference.
    I have no idea what the problem can be but Leopard used to work fine. What on earth have Apple done to screw it up and how can it be corrected.

    That's fine, but every time it crashes it automatically sends a report to Apple. Must have posted about eight so far. The point is, how long do I have to wait before a solution arrives and what am I supposed to do in the meantime. You pay good money to upgrade and find that you have gone backwards in some respects. It wouldn't be so bad if you could uninstall the upgrade easily but that could put me into greater trouble.

  • Error When Trying To Send MMS via email

    Ive been trying to send an MMS via email. Ive got it to work a couple times but other times I get a message that says: MAILER-DAEMON.....etc....remote host said: 550 SMTP connection refused [BODY]"....
    I sent the pic message to a verizon phone by emailing to [email protected]
    please help. thanx.
    kev

    I'm not sure why a Verizon subscriber not updating the PRL for their phone affects this, but it can.
    As already provided, ask the Verizon subscriber to update the PRL for their phone per the instructions included with this link, which should resolve the problem.
    http://www.verizonwireless.com/care/popups/prl.html

  • Unknown Error When Trying to Send & Collaborate Live

    When I try to share a file using Send & Collaborate Live, I get "an unknown error has occurred" in Acrobat while trying to share a document. I get another message after closing out the error message dialog box that tells me Acrobat "could not save this PDF file with collaboration enabled." Any idea on what is happening?

    Me too - same thing. It eventually continues to successfully upload after I "OK" the error window. Today, a client can't open the PDF without being prompted for a password, although I've sent it as an open file to anyone who knows the link. I'm wondering if that's tied into this error, although another client is having no problem commenting on their shared PDF even though I've been getting that unknown error for a few weeks now. Help anyone?

  • Why do I get an error when trying to send email?

    When I try to email a photo directly from iPhoto, I get an error message that tells me that server is unable to identify email name and password. WHY?
    I verified and email address and password are correct>
    Also, I have listed to email addresses on my MAC a Gmail address and a Comcast (other) account, but when I click on stamp for email on my desktop it opens both mailboxes in one place. Is there a way to separate them.
    Any answer and help provided will be greatly appreciarted.

    Have you ever tried to access email via your iPhone in the past with this service? Has it ever worked? I'm looking at their support page and cannot find any information regarding access via a mobile device. I'm wondering since it is a satellite service that you cannot access their domain from cellular service. I'm not positive, but a search of their support page is not yielding much information.
    Also, the incoming server is not your problem. It is the outgoing server or SMTP. According to the settings, it should be smtp.everyone.net. It does not use SSL for the outgoing server, and the username is your entire email address and then your password.
    You should be able to use the information for the Mac mail that I found in this link. http://www.skybeam.com/support/helpful-guides/email-support/mac-mail/ If that doesn't work, I would call their support phone number and ask about using their mail on a mobile device.

  • Remote Desktop Services Error when trying to send a message to a user in the collections

    We are implementing RD for thin clients and when I try to send a message to a user I get an error that states,: Unable to send a message to session X on (SERVER NAME.COM). WTS API Failed
    Is there a service that needs to be turned on?
    Thanks EPK

    Hi,
    Thank you for posting in Windows Server Forum.
    Before sending message please check following considerations.
    - You must have Message special access permission to send a message to a user.
    - You can send messages only to users whose sessions are in the active or connected state.
    - You can send a message to a user session in Remote Desktop Services Manager by using the Send Message action.
    Send a Message to a User
    http://technet.microsoft.com/en-us/library/cc754124.aspx
    Else you can also try below script and check the result.
    Send-NetMessage - Net Send / Msg.exe
    http://gallery.technet.microsoft.com/scriptcenter/Send-NetMessage-Net-Send-0459d235
    Hope it helps!
    Thanks.
    Dharmesh Solanki

  • Mail delivery error when trying to send document to hpeprint. I know the email address is correct

    I just got the HP8600.  I set up eprint according to the instructions.  When I email a document to the printer, I get a Mail Delivery error:
    This message was created automatically by the mail system (ecelerity).
    A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:
    >>> [email protected] (reading confirmation): 550 5.7.1 Command
    >>> rejected
    I know the email address is correct.  I don't know what to do to get this to work.

    The Q.com provider seems to have issues sending to our servers for some reason. Other email providers will work fine like you've found with your gmail account. The best workaround at this time is to send from your gmail account if possible.
    Jon-W
    I work on behalf of HP
    Please click “Accept as Solution ” on the post that solves your issue to help others find the solution.
    Click the KUDOS STAR on the left to say “Thanks” for helping!

  • E mail error when trying to send email

    I have an application that I want to send an email alert when there is an alarm condition. I have an email VI that works when run outside of my application. When I try to have my application load the VI into a form and run I get the following error:
    Error 26: occured at set cursor icon (icon pict).vi
    How can I fix this?

    Hi Ernie,
    Would you be able to provide more details on this issue.?  I am not quite sure what you mean by "have my application load the VI into a form."  Can you post your VI here or a screenshot?

  • Smtp error when trying to send email

    Hi,
    We just moved and our airport network (connected to a T1) was working; however, now we cannot send email from either my ibook or my husband's pc when using Outlook or THunderbird, as we both get the same SMTP error. It does work when using webmail though. Everything else works fine -- any suggestions on how we can resolve this?
    Thank you!
    Evelyn

    This error is only caused when the SMTP Settings are typed in incorrectly.
    I suggest you do one of 2 things double check both computers and make sure that a comma has not been placed in instead of a period.
    If that isn't the case, Sometimes you may be required to delete the Account settings and start all over by creating a new account to activate your Mail. It isn't that unusual when first setting up a new Mail and account to have this glitch. So delete the Account and be sure you have everything written down form your Isp to create the new Account. It will be exactly the same as the one you deleted.
    Don

  • Upload Error when trying to send large files with Adobe Send

    I am a paid subscriber of Adobe Send and should be able to send up to 2GB of files. I am not able to send even 1GB. I have compressed all files into a .zip folder.
    I then tried splitting the files into 2 separate .zip folders at about 500MB each, and still got the upload error again after waiting for the entire file to upload. A lot of wasted time now.
    It's not reasonable for me to send all of the files piecemeal to my client.
    What is going on?
    Thank You!
    Dave

    Here are some screenshots:

  • SMTP Error when trying to send: saveSmtp failed

    We installed iplanet messaging 5.2 on our cluster and when we try to send mail through the web interface we get an error that just says SMTP error. The logs displays these error messages:
    Network Warning: saveSmtp: connect() failed
    General Warning: saveSmtp failed: SMTP Error
    If anyone knows what is causing this please help me out.
    Thanks,
    RM

    Use configutil and make sure service.http.smtphost is set to your SMTP server. It defaults to localhost and you probably don't have anything listening on localhost:25.
    -t

Maybe you are looking for

  • Help needed for newbie EJB

    Hi, all I am a newbie in EJB and I am following the example in the URL: http://www.huihoo.com/jboss/online_manual/3.0/ I am working on the 'interest' example in the first chapter. When it come to 'Packaging and deploying the bean', I got some meaage

  • Split the lines in SLA

    Hi, We are using Project Accounting, Fixed Assets and General Ledger on 12.1.3 platform. When we capitalize the asset and generate asset lines, we send the information to Fixed Assets from where the accounting entries get posted to General Ledger thr

  • Does rendering previews larger than max native resolution benifit you.

    Hi, I have Adobe Lightroom 4.3.  I like to know if rendering standard previews, larger than the max native resolution of my LCD display (1680x1050), will Help me, if I look edit photos at great than 1:1 ratio. IE, 2880, 2040, 1680 etc.. In some cases

  • My wifi is not working on my iphone

    hi my name is chevaughn My wifi is not working when i upgrade my iphone

  • ITunes shuts down Internet after installation & Firewall

    Okay, i have a very weird problem and i REALLY need this fixed. I am having issues after installing iTunes. I download iTunes for Windows 7 64 bit off of the Apple website, it downloads fine and i open up the setup and it installs fine, after install