Save email message in db

I try to save content of email in db,
Message msContent=message.getContent();
after
java.io.InputStream mesAsInputStream=(InputStream)msContent;
But I receive exception Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.io.InputStream
I understand that there are 2 types of messages first one a simple string, and second a multipart.
But I would like save as object in db indipendent from type of message.
But for save in db it need cast to InputStream. Could you please me say how it can be done correct?

Hi,
The Message is an interface which extends another interface which is Part interface. Now the implementation of the Message ( the class implementation ) is not an InputStream
The best thing to do is to serialize the object as a stream of bytes and save it into the database as blob datatype
or you can send it into the ByteArrayOutputStream and convert the byte stream to string using a characterset which is pretty standard which you may change if you are using different characterset
public static void printToStream(Message m) throws IOException, MessagingException {
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
          m.writeTo(outputStream);
          String message = outputStream.toString("UTF-8"); // character encoding set
          // now save the message into the database
     }Regards.
Alan Mehio
London, UK

Similar Messages

  • Can no longer save email messages to my files

    Before upgrading to Mavericks, I could open an email message from a client, click Save As, select a folder, then save the message as a text file to the appropriate folder on my hard drive. It seems I can no longer do that. I always get a Mail error message saying "Names longer than 31 characters are not supported on the destination volume."(Even when the name is already shorter than that, I go through the exercise of shortening it.) After doing that, I click Save. Then I get an error saying "Error: Could not save to path...." which, incidentally, goes haywire part of the way through and takes it down a path that is a completely wrong folder for another client. Regardless, it doesn't save.
    I've tried completely renaming the file. I've tried everything I can think of.
    This used to be SO SIMPLE:  Just click Save As, select the appropriate folder, then click Save.
    In Mavericks, do I need to convert this email message into a Word document in order to save it to a folder?

    Please follow these directions to delete the Mail "sandbox" folders. In OS X 10.9 there are two sandboxes, while in 10.8 there is only one. If you're running a version older than 10.8, this comment isn't applicable.
    Back up all data.
    Triple-click anywhere in the line below on this page to select it:
    ~/Library/Containers/com.apple.mail
    Right-click or control-click the highlighted line and select
              Services ▹ Reveal
    from the contextual menu.* A Finder window should open with a folder named "com.apple.mail" selected. If it does, move the selected folder—not just its contents—to the Desktop. Leave the Finder window open for now.
    Log out and log back in. Launch Mail and test. If the problem is resolved, you may have to recreate some of your Mail settings. You can then delete the folder you moved and close the Finder window.
    This action will delete any custom Mail stationery that you have created. If you want to preserve it, ask for instructions.
    If you still have the problem, quit Mail again and put the folder back where it was, overwriting the one that may have been created in its place. Repeat with this line:
    ~/Library/Containers/com.apple.MailServiceAgent
    Caution: If you change any of the contents of the sandbox, but leave the folder itself in place, Mail may crash or not launch at all. Deleting the whole sandbox will cause it to be rebuilt automatically.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
              Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.

  • Mail crash when trying to save email message

    I installed OS10.5.1 recently and yesterday mail starting crashing whenever I'd try to save an email message ("save as" or shift apple s). Based on one post, I ran a verify and repair disk permissions (from the hard drive, not from the startup disk) but no remedy. The beginning of the crash reports reads: Process: Mail [150]
    Path: /Applications/Mail.app/Contents/MacOS/Mail
    Identifier: com.apple.mail
    Version: 3.1 (914)
    Build Info: Mail-9140000~1
    Code Type: PPC (Native)
    Parent Process: launchd [85]
    Date/Time: 2008-01-18 08:36:00.182 -0600
    OS Version: Mac OS X 10.5.1 (9B18)
    Report Version: 6
    Exception Type: EXCBADACCESS (SIGSEGV)
    Exception Codes: KERNPROTECTIONFAILURE at 0x00000000bf7fffe0
    Crashed Thread: 0
    Any ideas on how to repair this would be appreciated. Thanks.

    Hi Farid Shahin.
    Verify/repair the startup disk (not just permissions), as described in the following article, in case there is something amiss in the filesystem:
    The Repair functions of Disk Utility: what's it all about?
    You’d get better results using Eudora Mailbox Cleaner to do the conversion.
    Eudora Mailbox Cleaner requires rebuilding the imported mailboxes in Mail afterwards. Instead of rebuilding them one by one, you can re-create the entire index as follows:
    1. Quit Mail if it’s running.
    2. In the Finder, go to ~/Library/Mail/. Make a backup copy of this folder, just in case something goes wrong, e.g. by dragging it to the Desktop while holding the Option (Alt) key down. This is where all your mail is locally stored.
    3. Locate Envelope Index and move it to the Trash. If you see any other “Envelope Index”-named file there, delete it as well.
    4. Open Mail. It will tell you that your mail needs to be “imported”. Click Continue and Mail will proceed to re-create Envelope Index — Mail says it’s “importing”, but it just re-creates the index if the mailboxes are already in Mail 2.x format.
    Note: For those not familiarized with the ~/ notation, it refers to the user’s home folder. That is, ~/Library is the Library folder within the user’s home folder, i.e. /Users/username/Library.

  • Applescript to save email messages feasible?

    Can someone tell me if this is feasible? If it is I might try and learn Applescript to write it.
    At work we have a problem trying to get people to file emails correctly. We want each email to be saved to their respective project folders on the server as RTFs (or ODFs).
    So I'm wondering if the following Applescript is feasible?
    1) Open a read email, normal behaviour would ensue
    2) Open an unread email and a separate dialogue window pops up, prompting the user to choose a filename and somewhere to save the message (this should include the ability to choose a filename by clicking on existing files, as in a normal save dialogue).
    3) If the email has attachments the same pop-up window, or a separate one, would prompt the user to choose a (possibly different) folder to save the attachments, and allow the user to choose which attachments to save, including none.
    4) Lastly the the same pop-up window, or a separate one, would prompt the user for a folder within Mail to move the message to.

    A native AppleScript possibility, - although, not via a single window
    With respect to '2) Open an unread email ...' - one could create a 'Rule' in 'Mail' to execute an AppleScript script.
    The AppleScript script would open each e-Mail message, present a 'choose folder' dialog box (consult 'Library' windows' 'StandardAdditions.osax' dictionary), followed by a 'display dialog' (with a 'default answer ""' entry) for file name entry, The information from the two (2) dialog box'es would be concatenated to form a new file path.
    With respect to '3) If the email has attachments ...' - the list of attachments, of each e-Mail message, would be looped (repeat ... end repeat) through - with a 'choose folder' dialog displayed as the destination of the attachment. Naturally, if the attachments' name is to be user editable - a display dialog (with a 'default answer '""' entry) would be required. Again, the information from the two (2) dialog box'es would be concatenated to form a new file path.
    Finally, with respect to '4) ... prompt the user for a folder within Mail to move the message to.' is possible by a 'choose from list' dialog box; where the list is of the 'Mailbox' names of 'Mail'.

  • Osx mavericks - cant move or save email messages

    In all the older operating systems it would allow a user to drag an email message from Mail to anywhere you wanted to stash it; the desktop or any folder. Now with Mavericks it won't allow any moving or saving of an email message outside of the Mail apps internal folders.

    I restarted the iMac and now it seems to allow this operation - so I consider this problem resolved for now.

  • Saving email message to a file

    I was trying to save email messages (not just message text, but everything) into a file. But I got exception stating that com.sun.mail.pop3.POP3Message is not serializable. Is there any workaround to save email object into a file?

    This writes the message as an object to a file.
    It is fully functional - use this in one of my programs.
    try{
    email = (MimeMessage)message;
    file=new File(fileName);
    outFile=new FileOutputStream(file);
    outStream=new ObjectOutputStream(outFile);
    e.writeTo(outStream);
    closeStream();
    outStream.close();
    outFile.close();
    catch(Exception ex)
    {/error writing file}
    Good Luck!
    jared

  • Saving email messages

    On my iPad my mail service is via a POP account. I understand that I cannot add any additional mailboxes to the Mail app.
    Is there a way to save email messages somewhere else besides the Inbox?
    Thanks, Jim

    https://itunes.apple.com/us/app/altamail/id328890658?mt=8
    This app will allow you to do what you are wanting to do.
    BEST app on the app store for email BAR NONE
    The press are convinced!
    ========================
    Incredible iPhone Apps for Dummies "The more e-mail you send & receive on your iPhone/iPad, the more you'll appreciate AltaMail "
    AppShouter: "this app exp&s the possibilities for mail"
    iPhone Apps Finder: "a very solid business app - 9/10"
    ArticleClick: "....bottom line is that this app exp&s the possibilities for mail on your iPhone or iPad"
    I use it and LOVE it. Wish I had created it lol
    the one I made only archives better than the stock apple app but eh this is the Best so why try reinventing the wheel =)

  • How can i leave a copy of email message after receiving it on outlook, how can i leave a copy of email message after receiving it on outlook

    i have a problem that i cant save email message on both my iphone and on outlook on pc

    So even though he can see everything he's ever gotten in All Mail, he still wants in in Inbox?  I realize the how to do it is a little bit of a stumper and it shouldn't be so difficult... but honestly, I think the more relevant question would be Why? Why would anyone in their right mind want to do that?
    How does his Blackberry currently access his Gmail account? It should be a simple matter to duplicate the settings. It's undoubtedly just using POP and not deleting the originals as they are downloaded.
    Here's what's going to happen if that's the case. The very first time he sets up a new device... phone, pc, doesn't matter, to use POP, it's going to download every e-mail he's ever gotten unless he goes in and tells Gmail otherwise.

  • In an eMail message, when I attempt to save two photos by clicking the 'Save 2 Images' link, not the 'Save Image' link, the images are not saved. (I use I I apologize for the late notice, butOS7 on IPhone5). Is this feature broken?

    In an eMail message, when I attempt to save two photos by clicking the 'Save 2 Images' link, not the 'Save Image' link, the images are not saved. (I use I I apologize for the late notice, butOS7 on IPhone5). Is this feature broken?

    Please don't post the same question multiple times!

  • Error Message  when trying to "Save Email as Activity" on Outlook 2007

    Hi all,
    This is a problem that we have logged with SAP, but they cannot find any reasons as to why we are having the problem. So I'm hoping someone here might be able to shed some light...
    After logging onto SAP through Outlook:
    When "Saving an email as Activity" using the Outlook ADDON, we get the following error message:
    AppName: bo_syncext.exe      AppVer: 8.0.0.49      ModName: bo_syncext.exe
    ModVer: 8.0.0.49      Offset: 000cc9d5
    This does not seem to work on any of our computers, except one!
    He is a Superuser, and he can save emails on his PC only.
    I can also save the emails, if I am logged on his computer, and am set up as a Superuser. I cannot if I am not a Superuser.
    He and I cannot send emails as a Superuser on my PC.
    This would lead me to think that it is a problem with our PC settings (security settings?).
    Has anyone else had this problem?
    Outlook version: 2007 (12.0.6514.5000) SP2 MSO (12.0.6425.1000)
    SAP Business One 2007.
    Many thanks
    Shaoni

    Hi
    I also have the same issue.
    I can save an email as an activity for only one user, this user is a super user.
    If i log on to that users machine as them, then sap as a user with the issue change them to a super user it works.
    However logged on to any other machine it won't work. We get the error message ;-
    Outlook itegration - error signature - AppName bo_syncext.exe, AppVer 8.0.0.49  Mod Name ntdll.dll ModVer 5.1.2600.3520
    Has anyone fixed this on a system ???

  • I am in New Zealand and when I type up a rather long email to send back home, the send button does not light up by the time I finish and I cannot send the email and can't seem to save the message or anything and then as soon as I touch a button, poof, gon

    Can anyone tell me why when I type a very long email, the send button is not highlighted anymore when I am done and I can't send the message? And I can't seem to save the message or anything and as soon as I touch a button, I lose the whole thing. Any suggestions?

    Have you tried typing and saving using Notes or word processing Apps before sending message?

  • How can I delete an attachment from a received email but save the message?

    Hi all, how can I delete an attachment from a received email but save the message?*

    Over the years this issue crops up again and again. Here are the cases I know about:
    Case 1 - it simply doesn't work
    I have a message in my inbox with a jpeg of about 300Mb. Select message, choose option "remove attachment" which is not greyed out, and it does not work.
    Case 2 - it works if you save the message first
    I move the message from the inbox to a mail box. Open the mailbox (select), select the message, choose option "remove attachment", result: the attachment is removed, a small text file is added and an error appears in the message "missing plug-in". The message size is reduced from 300Mb to a few bytes.
    Case 3 - the option "remove attachment" is greyed out.
    I've googled this at least 10 times and read all the advice about editing various files from the library and all the other hacks. The simple truth here is that the user should not be inconvenienced by such inappropriate behaviour. We're not used to this from Apple any more, not since OS X. Even Windows does this stuff painlessly. In fact this kind of function is something that Outlook and Exchange do incredibly well. If they didn't the corporate world would have ground to a halt.
    My point: the remove attachment option should work all the time and should be redesigned. Right-click + save as + delete in the message would be a hundred times easier.

  • How do I send a group email messages then save it for later???

    How do I send a group email messages then save it for later???is there a way that i can save couple of people for whenever want to send an email for them by clicking on my save group get access easily to specific people.
    Thankssss

    You can set up email groups in Contacts. The articles says Address Book (Contacts old name), but it still works.
    Contacts – Create Mail Group

  • Can I save an email message as .eml file and open it using outlook?

    Hi all,
    I use the following codes to save the received email message as .eml files:
    Session session = (Session)map.get("CURRENT_SESSION");
    //InputStream is = msg.getInputStream();
    MimeMessage mm = new MimeMessage(session, msg.getInputStream());
    String filePath = AttachmentProcess.getInstance().getFilePath(attachmentId);
    String fileName = AttachmentProcess.getInstance().getFileName(attachmentId);
    mm.saveChanges();
    mm.writeTo(new FileOutputStream(new File(filePath, fileName)));
    But when I open it using window live mail, its content looks like this:
    ------_=_NextPart_001_01CA7E32.F3122E40
    Content-Type: text/plain;
    charset="us-ascii"
    Content-Transfer-Encoding: quoted-printable
    =20
    New interaction from Thomas Lo on assignment "Assignment Enhancement":
    =20
    Interaction body goes here
    =20
    =20
    When this email is sent to [email protected], it will be filed into
    assignment "Assignment Enhancement" automatically.
    Please don't modify this line. [ID: ASIGMT 51]
    ------_=_NextPart_001_01CA7E32.F3122E40
    Content-Type: text/html;
    charset="us-ascii"
    Content-Transfer-Encoding: quoted-printable
    <html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
    xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
    xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
    xmlns:x=3D"urn:schemas-microsoft-com:office:excel" =
    xmlns:p=3D"urn:schemas-microsoft-com:office:powerpoint" =
    xmlns:a=3D"urn:schemas-microsoft-com:office:access" =
    xmlns:dt=3D"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" =
    xmlns:s=3D"uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" =
    xmlns:rs=3D"urn:schemas-microsoft-com:rowset" xmlns:z=3D"#RowsetSchema" =
    xmlns:b=3D"urn:schemas-microsoft-com:office:publisher" =
    xmlns:ss=3D"urn:schemas-microsoft-com:office:spreadsheet" =
    xmlns:c=3D"urn:schemas-microsoft-com:office:component:spreadsheet" =
    xmlns:odc=3D"urn:schemas-microsoft-com:office:odc" =
    xmlns:oa=3D"urn:schemas-microsoft-com:office:activation" =
    xmlns:html=3D"http://www.w3.org/TR/REC-html40" =
    xmlns:q=3D"http://schemas.xmlsoap.org/soap/envelope/" =
    xmlns:rtc=3D"http://microsoft.com/officenet/conferencing" =
    xmlns:D=3D"DAV:" xmlns:Repl=3D"http://schemas.microsoft.com/repl/" =
    xmlns:mt=3D"http://schemas.microsoft.com/sharepoint/soap/meetings/" =
    xmlns:x2=3D"http://schemas.microsoft.com/office/excel/2003/xml" =
    xmlns:ppda=3D"http://www.passport.com/NameSpace.xsd" =
    xmlns:ois=3D"http://schemas.microsoft.com/sharepoint/soap/ois/" =
    xmlns:dir=3D"http://schemas.microsoft.com/sharepoint/soap/directory/" =
    xmlns:ds=3D"http://www.w3.org/2000/09/xmldsig#" =
    xmlns:dsp=3D"http://schemas.microsoft.com/sharepoint/dsp" =
    xmlns:udc=3D"http://schemas.microsoft.com/data/udc" =
    xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" =
    xmlns:sub=3D"http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/"=
    xmlns:ec=3D"http://www.w3.org/2001/04/xmlenc#" =
    xmlns:sp=3D"http://schemas.microsoft.com/sharepoint/" =
    xmlns:sps=3D"http://schemas.microsoft.com/sharepoint/soap/" =
    xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" =
    xmlns:udcs=3D"http://schemas.microsoft.com/data/udc/soap" =
    xmlns:udcxf=3D"http://schemas.microsoft.com/data/udc/xmlfile" =
    xmlns:udcp2p=3D"http://schemas.microsoft.com/data/udc/parttopart" =
    xmlns:st=3D"" xmlns=3D"http://www.w3.org/TR/REC-html40"
    xmlns:ns2=3D"http://schemas.microsoft.com/sharepoint/soap/workflow/"
    xmlns:ns3=3D"http://schemas.microsoft.com/office/2006/digsig-setup"
    xmlns:ns4=3D"http://schemas.microsoft.com/office/2006/digsig"
    xmlns:ns5=3D"http://schemas.openxmlformats.org/package/2006/digital-signa=
    ture"
    ------_=_NextPart_001_01CA7E32.F3122E40--
    Can anybody help me ?

    This works now by coping all headers to the new MimeMessage from the coming message.
    But one issue occurs when the email contains attachments.Because all attachment will be display on the email body.
    What happens?

  • I am trying to determine how I can take an email without an attachment and save it to a folder.  I am not able to paste the message anywhere.  I can copy but to no avail.  I want to set up folders in email to move and save emails.  How can this be done?

    I am trying to determine how I can save emails into folders in my email account.  No ability to create a folder to move an email over into.  How can I do this?

    If you are using iPad Mail app, in the left hand column tap the arrow in the top left corner until you return to where your main email address appears. This is the main account screen.
    Then tap the email address/account once.
    In the left column in the upper right, tap the Edit button.
    At the bottom of the left column/panel there is a New Mailbox button.
    Tap the button. At the top of the left column, a keyboard entry field appears.
    Thiis is where you tap and enter the name of your new Mailbox folder.
    Once done naming, click the done button at the top right of the left column and you are done.
    This is how you add additonal mailbox folders to your email account.
    Once the mailbox folders you need are created, you can return to any email entry, Tap the Edit button in the upper right of the left column, again. A button appears next to all the emails in the left column.
    Tap the buttons for the ones you wish to move to a particular mailbox folder, at the bottom of the left column, choose the Move button, then pick the mailbox folder to move the emails to and they will automatically move to that mailbox folder.

Maybe you are looking for