Modify existing Message

Hi all,
I need to change text/html part of message which I have in mail format. How to do this easily without loosing other parts of message?
Or maybe you know some better way to create kind of simple proxy for SMTP which would add and replace some text in HTML part of email?
So far I am reading message from plain stream of mail text representation (got it from Subethamail SMTP server) into JavaMail Message object. I had problem, when my changes to message were not reflected - I posted question on http://stackoverflow.com/questions/7674775/how-to-modify-existing-java-mail-mimemessage-body-parts/ and solved this one by calling message.saveChanges();
The issue is that when I call message.saveChanges() headers seams to be lost - especially those around Content Type and Charset.
My code looks like this:
public void resend(InputStream data) throws Exception {
        Transport transport = mailSession.getTransport();
        MimeMessage message = new MimeMessage(mailSession, data);
        Object content = message.getContent();
        if (MimeMultipart.class.isAssignableFrom(content.getClass())) {
            MimeMultipart mimeMultipart = (MimeMultipart) content;
            for (int i = 0; i < mimeMultipart.getCount(); i++) {
                MimeBodyPart bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(i);
                if (bodyPart.getContentType().startsWith("text/plain")) {
                    String cnt = updateContent((String) bodyPart.getContent());
                    System.out.println("ContentType = " + bodyPart.getContentType());
                    System.out.println("Content = " + cnt);
                    String contentType = bodyPart.getContentType();
                    System.out.println("Updating content type to = " + contentType);
                    bodyPart.setContent(cnt, contentType);
                } else if (bodyPart.getContentType().startsWith("text/html")) {
                    String cnt = updateContent((String) bodyPart.getContent());
                    System.out.println("ContentType = " + bodyPart.getContentType());
                    System.out.println("Content = " + cnt);
                    String contentType = bodyPart.getContentType();
                    System.out.println("Updating content type to = " + contentType);
                    bodyPart.setContent(cnt, contentType);
        } else {
            String cnt = updateContent((String) message.getContent());
            System.out.println("ContentType = " + message.getContentType());
            System.out.println("Content = " + cnt);
            String contentType = message.getContentType();
            System.out.println("Updating content type to = " + contentType);
            message.setContent(cnt, contentType);
        message.saveChanges();
}Mark on Stackoverflow suggested that problem is in bodyPart.setContent(cnt, contentType); call...
Hope that makes sense for you... and you will be able to help me...
Thanks in advance
Konrad
Edited by: 890134 on 2011-10-07 08:29

JavaMail wasn't really design to support "editing" of existing messages.
That's caused some problems over the years and I've had to fix a number
of bugs in this area. The current version (1.4.4) definitely works better
than older versions, but I won't be surprised if there are still bugs.
Even so, your code is making a number of invalid assumptions about the
structure of messages. I would suggest looking at the msgshow.java
demo program. It includes code that visits all the parts of a message.
It should be straightforward to extend that code to detect the parts you
want to modify and to change the content of those parts using the
setContent (or setText) method.
If it's still not working for you, provide more detail about what you're doing,
including a same message. (Send the details to me at [email protected]
if you prefer.)

Similar Messages

  • Modifying existing mail rules now even worse with Mavericks 10.9.1

    Mail nightmares continue with Mavericks update 10.9.1 installed. In fact, the nightmare gets bigger. The story goes like this.
    Prior to Mavericks, I created a stack of rules to move Mail messages from the Inbox to designated Mailboxes, e.g. messages from Friends would be moved to a Friends mailbox. Everything worked fine.
    Along comes Mavericks, and when I Edit a rule to add a new recipient, and Apply that rule change to Move existing messages to another mailbox, messages would be Copied instead of being Moved, even though Move was the only action selected.
    Now with Mavericks 10.9.1, nothing happens when I Edit an existing rule and then Apply the rule change to an existing message. The messae just sits in the Inbox and does not appear at all in the Mailbox I want to move it to.
    How do I modify mail rules to move a message to another mailbox, then apply that rule modification to existing messages?

    Hi BG 29,
    Unfortunatelly you are not the only one with this problem. I am in the same situation with the exception that once I create the rule the new incoming messages will go to the designated mailbox. If you want to create a new rule, the message will just copy, not move to the mailbox. I contacted Apple support and a representative called me back and asked me to do all kind of stuff, but no luck. I was hopping that the update to 10.9.1 will solve this, but again no luck. I gave up in trying....I am waiting for the next update and hope for the best.

  • Problem in modifying existing records in dbtab

    Hi Experts,
    I am doing a report where I have created two dbtab's , one for data getting saved and
    other for fetching data and modifying exsiting records..
    For eg - let ZABC be the table where I need to insert or update records and ZXYZ is the table where
    I need to fetch and modify existing records.
    Now my probelm is :
    In case of inserting new records (multiple records ) into my dbtab ( ZABC ) its working ,
    but modifying existing records in another dbtab (ZXYZ ) its not wroking !! plz advice !!
    If my select querry for modifying exsiting records is:
    SELECT *  FROM ZXYZ  INTO TABLE ITAB WHERE MATNR EQ S_MATNR.
    *****then its inserting a newline along with the existing records.
    but when my querry is,
    SELECT single *  FROM ZXYZ  WHERE MATNR EQ S_MATNR.
    then its modifying the existing records, but only the first record.
    Loop at itab.
    if sy-tabix  = 1.
    zabc-matnr = matnr.
    zabc-idnrk  = idnrk.
    zabc-budat = s_budat.
    zabc-menge = menge1.
    ZXYZ-menge = ZABC-Menge + MENGE1.
    ZXYZ-BALC  = ZXYZ-Menge   -   MENGE1.
    ELSEIF sy-tabix  = 2.
    zabc-matnr = matnr.
    zabc-idnrk  = idnrk.
    zabc-budat = s_budat.
    zabc-menge = menge2.
    ZXYZ-menge = ZABC-Menge + MENGE2.
    ZXYZ-BALC  = ZXYZ-Menge  -  MENGE2.
    ELSEIF sy-tabix  = 3.
    zabc-matnr = matnr.
    zabc-idnrk  = idnrk.
    zabc-budat = s_budat.
    zabc-menge = menge3.
    ZXYZ-menge = ZABC-Menge + MENGE3.
    ZXYZ-BALC  = ZXYZ-Menge   -  MENGE3.
    ENDIF.
    INSERT ZABC.
    IF SY-SUBRC EQ 0.
    MODIFY ZXYZ.
            IF SY-SUBRC = 0.
              MESSAGE : I002 WITH 'RECORD CREATED'.
                ENDIF.
    ENDIF.
    Please advice
    Karthik
    Edited by: Karthik R on Aug 24, 2009 9:42 PM

    Hi,
    This is because in the second case you are not selecting records into an internal table.
    As a result only the first record which satisfies the where condition is fetched.
    Check if the program goes into the loop when you write second select query.
    KR Jaideep,

  • Modify DSN Messages without using Shell.

    Hi Guys..Wanna Know where are DSN Messages actually stored on the file-system ? Although using " Get-SystemMessage -Original " gives you a logical path and detailed content of system default DSN Messages but is there a way out to modify DSN Messages
    without using shell from actual file-system itself. Please suggest ?

    Hi,
    Based on my knowledge, we can only use command to modify DSN messages. This is something that has to be done from the Exchange Management Shell.
    Here is an article about how to modify the DSN message for your reference.
    View or Modify an Existing Custom DSN Message
    http://technet.microsoft.com/en-us/library/bb125230(v=exchg.141).aspx
    Best regards,
    Belinda
    Belinda Ma
    TechNet Community Support

  • Updates are not installing already exists, will modify existing instance.

    hi all
    I have  published updates via scup and seeing below message in update store log its  not updating old version what is this message means
    Update status from update (c2f61a88-730e-47af-8119-6e3b5a789764) already exists, will modify existing instance.
    ankith

    That just means that the client already scanned for compliance, scanned again now and found out that the state for that patch (installed, required, etc) has changed.
    Torsten Meringer | http://www.mssccmfaq.de

  • Best Practice to migrate existing Message/Central Instance to new hardware?

    I've done some searching for this, but it all seems to be fairly old (I found one decent thread from 2008, but it just seemed outdated).  I would like to get some updated info & suggestions on a process to follow for this task.
    Here is some info about the current config:
    I have an existing SAP ERP 6.0 EHP5 system.  SID "XYZ"
    Everything is currently running on Windows x64.
    ABAP only config.
    It is currently setup as a distributed system.
    DB server is SQL, which is running on its own hardware as a dedicated DB server.  I don't need to touch this.
    Uses logon groups to distribute the load between 3 App servers.
    One of the App Servers is setup as the Message/CI server. This is what I am wanting to move to VM hardware.
    The other two App Servers are setup just as Dialog Instances.  VM already.  I don't need to touch these.
    What I am wanting to do:
    I am wanting to migrate the existing Message/CI server to VM hardware to get the current Message/CI system off of very old hardware.
    I need to keep the system with the same name & IP.
    I do not need/want to mess with the DB server at all. 
    Need to minimize downtime as much as possible.
    I do NOT want to go to an HA environment.  That is a different project for the future.
    Suggestions? I would like to hear what some of you have done.
    Minimize downtime?  I have a short maintenance window of a few hours coming up in the next few months, and would like to do this changeover during that downtime.
    How do I handle setting this up on the new hardware using the same name & IP, especially with the existing system still running.
    What I think I need to do: (Some of these may be out of order, which is why I'm asking for suggestions)
    Setup new Windows VM server, named differently than current Message/CI server (Done already).
    Run SAPINST to run Global Host Preparation on the new Windows VM server.
    Run SAPINST to setup ASCS Instance on the new Windows VM server.
    Skip the Database Instance installation, since I already have one running.
    Run SAPINST to setup Central Instance on the new Windows VM server.
    Copy all of the appropriate profile parameters that were on the old server.
    Start SAP and make sure everything is running and working correctly.
    Copy all job, spool files, etc. from the old server.
    What needs to be done in between those steps for the server rename & IP changes?
    Which of these steps can I do in advance of my maintenance downtime window, without it affecting the currently running system?
    I have a test environment that I am going to test this with.  I'm just trying to get a jump start on my instructions, so that I can hopefully do this quickly and easily.  I'm very comfortable doing the installs.  Just needing some guidance on how to handle this case.
    I'm open to suggestions, and any links you can send my way that show some more recent success at doing this.  Everything I keep finding talks about doing the migration for the DB.  I am not migrating my DB.  It is staying where it is.  I'm just wanting to migrate my Message/Central Instance to a VM, without affecting the users, and hopefully them never noticing the changes.
    Thanks!

    If you're using VMWare, there is a tool provided to virtualize existing systems.  Basically it makes a copy of the old system (while it is down) and recreates it as a VM with the same name, IP, etc.  I haven't double-checked to see if this process is 'officially' supported by SAP, and I don't know the technical details about how it's done or how long it will take (VMWare is managed by the Network Operations group in my team, so as the SAP sysadmin I'm basically a customer of theirs).  However, we have virtualized a few smaller systems that needed to get off failing hardware in a hurry and it worked very well, so I would expect it would for an SAP dialog instance as well.  As you're not copying a database, just the app server, it probably would fit within your maintenance window.
    If this route works for you, then there is no need to actually install the SAP system on the VM instance... you just copy the old server as-is, then make any adjustments required due to no longer needing old drivers, etc, plus potentially having different memory parameters.

  • Object does not exist :  MESSAGE OL 826 - Production issue

    R/3 release 4.6C
    Transaction: FB03
    Custom WF:  Triggering events: FIPP-CREATE  and FIPP-COMPLETED
    When we try to post a document (journal) the workflow gets triggered and reaches the approver. The approver approves it and then it gets posted.
    Here in this case, after the approval the workflow running into error with u201Cmessage OL 826 Object does not existu201D
    When I click on the message I get this information
    Object does not exist   :   Message no. OL 826                                                    
    Diagnosis :   You tried to create an instance of the object type EMPLOYEET with the
                        key 1234520080603. No instance of this kind exists.                   
                    PERNR u2013 12345
         Date      - 03.06.2008
    I checked this using the FM P_EMPLOYEE_CHECKEXISTENCE and it is working fine there. This FM is used in EMPLOYEET object for existence check.
    Initially I thought the problem was with document and the buffer but after checking u201Cdiagnosisu201D message, it confirms me that this is related to Employee.
    This is happening only to one employee and all other have NO issues.
    I have checked with HR team and they reckon everything is fine from their side.
    Since this is in Prod I am unable to debug and test.
    I was looking into the previous forums to find the solution but couldnu2019t find RIGHT one. Could you please suggest any solution for this ?
    Your help greatly appreciated.
    Sreethan
    Edited by: SAP User on Jun 12, 2008 12:13 PM

    Dear Mike/Martin,
            Could you please explain a bit about the authorization problem?
            PERNR    A, B, C, and D do the posting the docs through FB01 and PERNR  X usually do the approvals. the problem is happening onlyl with PERNR A ... if the approver has the auth problem then it could be same issue with other...  please correct me if I am wrong.
        As Martin suggested I have contacted HR team but they say .... they dont see anything different or changes for this EMP.  The personal record is coming from the EVENT FIPP-CREATE or COMPLETED so there is no manual interaction.
    Just guessing: if this is the problem for all the employees then what could be the reason ? guessing that in random it is happening to this emp. He has posted 6 docs....all of them have the same issue. I checked last 3 months records and I did see Couple of workflows in last 3 months with the same error....  so just thinking if this is the problem with all emp happens onlly ramdomly.
    Thoughts ??
    Thanks & Regards,
    Sreethan

  • My iMessage does not appear to be working. Every time I go to reply to an existing message it just appears as normal text. I have tried to create a new message but it still just defaults to normal messages. I have checked my settings but looks ok. Help?

    My iMessage does not appear to be working. Every time I go to reply to an existing message it just appears as normal text. I have tried to create a new message but it still just defaults to normal messages. I have checked my settings but it is all set up as it should be. Is there anything I've missed or could try? Thanks

    Try the following:
    In Finder, select the problematic volume and then press command-I.
    Expand the Sharing & permissions section if it's collapsed.
    If the section is locked, then unlock it by pressing the padlock button and then authenticating as directed.
    Tick/check Ignore ownership on this volume.

  • Hard Disk Not Exist message is displayed on cq10-400

    Hard Disk Not Exist message is displayed on cq10-400

    Sounds like the hard drive may have failed. If you are still in warranty HP will send a replacement. If not a retail hard drive can be used. Just be sure to get one of at least as large a capacity as the original to use HP Recovery Discs to reinstall Windows. For instance if you have a 320gb hdd you could use a 500gb but not a 250gb hdd.
    ******Clicking the Thumbs-Up button is a way to say -Thanks!.******
    **Click Accept as Solution on a Reply that solves your issue to help others**

  • Hard Disk Not Exist message

    Hard disk not exist message. What do I do now?

    Sounds like the hard drive has failed and will need to be replaced. If you are still in warranty HP will send a replacement. If not a retail laptop SATA hard drive can be used. Just be sure to get one of at least equal capacity as the original in order to use Recovery Discs. It can be larger, but not smaller capacity.For instance if you have a 500GB hdd you could use a 750GB hdd but not a 320GB hdd.
    If you need more help selecting/replacing the hdd post back with full Model & Product Number as listed on the Service Tag attached to bottom of laptop.
    How Do I Find My Model Number or Product Number
    ******Clicking the Thumbs-Up button is a way to say -Thanks!.******
    **Click Accept as Solution on a Reply that solves your issue to help others**

  • When I try to install Lightroom 5.6 I get a "Object already exists" message. I can't install it at all

    I updated Lightroom to 5.6 before going away for the weekend. When I came home I was unable to access lighroom all together. After searching I finally found how to chat with customer service (which I can't figure out again) and they told me to uninstall Lightroom, make a new Admin on my computer, and re-install it on the new Admin. When I did this I still get the same "Object already exists" message and it won't even install now.

    Do a clean (re)install:
    * Download a fresh Firefox copy from http://www.mozilla.com/firefox/all.html and save the file to the desktop.
    * Uninstall your current Firefox version and remove the Firefox program folder before installing that copy of the Firefox installer.
    * Don't remove personal data if you uninstall the current version.
    * Delete the files and folders in the %temp% folder.
    * It is important to delete the Firefox program folder to remove all the files and make sure that there are no problems with files that were leftover after uninstalling.
    Your bookmarks and other profile data are stored elsewhere (not in the Firefox program folder) and won't be affected by a reinstall, but make sure that you do not select to remove personal data if you uninstall Firefox.

  • Parked document 1000 700010042 2010 does not exist, Message no. FP076

    Hi,
    There is one Document which is not on tax return but made a entry in a GL account (VAT).
    When I display document from FB03 for fiscal year 2010 the transaction code FB03 is diverting to FBV3 and giving error message : "Parked document 1000 700010042 2010 does not exist" "Message no. FP076"
    I also checked the tables "BSEG" & "BKPF" where this document is visible to me also I checked the GL line items from FBL3N for the VAT GL where this document is showing in line items report, but when i double clik to display this documents again am getting screen of FBV3 with the same error message.
    can any one let me know what could be the problem? and how to resolve this issue?
    Many thanks in advance.
    Regards,
    Abdul

    Hi Venkata,
    Thanks for the information....
    Addition to the above information ... there are 3 line items are there in this document 1 - K (Vendor), 2 - S (GL).
    The strange thing I can see is against 1st line item (K-Vendor) there is a clearing document updated.
    So if there is a clearing document against vendor line that means this document is no more in parking ...
    I am not sure why system is performing like this...
    Can anyone help me on this ....
    Thanks in advance.
    Regards,
    Abdul

  • Command $TAB : message Transaction $TAB does not exist Message no. S#343

    when i use the command $TAB to refresh the buffers the system gives me the message
    " Transaction $TAB does not exist
    Message no. S#343 "
    In some systems it works as intended. How can i correct that position.

    try /$TAB

  • Infotype 2001 Record 00000000           000000000000000000000000000 does not exist Message no. PG225

    Hi,
    I am trying to  create a record in infotype 2001 but getting error
    Record 00000000           000000000000000000000000000 does not exist
    Message no. PG225
    This error not come before.  I have created many records for the last few months.
    Please suggest how to resolve.
    Regards,
    Pathi

    Hi Pathi,
    I guess this is because of Activity Allocation and Cost Assignment. Plz check the Number range assignment:
    PA05 for Number range assignment for additional time data
    PT12 for HR document posting
    Thanks'
    Gautam

  • Number range  for object MDTB does not exist - Message no. 61501

    Hi All ,
      I have done the necessary configurations in PP say
    Order Type
    Order Type Dependent Parameters
    Scheduling parameters for planned & production order
    Confirmation parameters
    Availabilty check etc
    and iam able to create planned & production order and confirma the production order.
    I want to configure for MRP: -
    Settings done are
    Have activeted planning file entry for all plants.
    When i run MRP system throws a error <b>Number range  for object MDTB does not exist - Message no.61501 </b>
    Is there anything to do with plant parameters OPPQ and Mrp Group OPPR.
    I just tried plant parameters,standard 0001 is not available for copying.
    Suggest me how to proceed to set MRP.
    Shankar

    Hi shankar
      it is a good practice while creating the plant copying the plant from the standard plant so that all the standard table enteries will be copied  for the plant as the standard plant is not there youcan think of copying from any other plant similar to your plant which has the required entry. else
    in SE16N  check the NRIV table for the Object MDTB. if enteris found then make the table entry with the help of abaper.
    hope this helps
    regards
    SK

Maybe you are looking for