none
Outlook (IMAP Acccount): Duplicate mails on server if i save mail body ( outlook 2007 & 2010 ) RRS feed

  • Question

  • Hi 

    I am working on outlook plugin.

    My program modifies mail body once it reaches in outlook ( adding footer with company logo )

    my code works fine, when i configured with POP3 account.

    but when i am having IMAP account, i am seeing continues mails coming on server also on client.

    (according to me same mail getting uploaded to server)

    and its because of following line 

    hr = pMail->put_HTMLBody(body);

    hr = pMail->Save();

    but its client requirement, i need to provide.

    but how i can avoid this duplication.

    your revert will help me a lot.

    many thanks.

    Thursday, July 23, 2015 2:53 PM

Answers

All replies

  • Hello,

    What code do you use exactly? Where did you get the pMail object?

    Thursday, July 23, 2015 3:02 PM
  • i am having unmnaged sample code source downloaded from below codeproject URL:

    http://www.codeproject.com/Articles/8016/Developing-an-Office-COM-add-in-with-VC-ATL

    This issue not occur with outlook 2013, below version i am getting duplicate mails.


    Thursday, July 23, 2015 3:14 PM
  • Where did you get the pMail object?

    > This issue not occur with outlook 2013, below version i am getting duplicate mails.

    Could you please be more specific? Is Outlook up to date?

    May we see the build number of your Outlook?


    Thursday, July 23, 2015 3:18 PM
  • Outlook Version: Outlook (14.0.4734.1000) MSO (14.0.4734.1000)


    Thursday, July 23, 2015 3:23 PM
  • Code is here 

    //ATL plumbing

    //In Class that defines addin inteface
    public IDispEventSimpleImpl<17, CAddin, &__uuidof(Outlook::ApplicationEvents_11)>


    _ATL_FUNC_INFO OnNewMail = {CC_STDCALL, VT_EMPTY, 1, {VT_BSTR}};

    SINK_ENTRY_INFO(17, __uuidof(Outlook::ApplicationEvents_11), 0xfab5, OnNewMailEx, &OnNewMail)

    //Header file function declaration
    STDMETHOD_(void, OnNewMailEx)(BSTR bstrEntryID);


    //CPP file function definition
    STDMETHODIMP_(void) CAddin::OnNewMailEx( BSTR bstrEntryID )
    {
    ATLTRACE("NewMail Entryid is %S\n", bstrEntryID);
    CComPtr<Outlook::_NameSpace> pNameSpace;
    HRESULT hr = E_FAIL;


    hr = m_pApp->get_Session( &pNameSpace );

    if( pNameSpace )
    {
    CComPtr<Outlook::_Store> pStore;

    hr = pNameSpace->get_DefaultStore( &pStore );

    if( pStore )
    {
    CComBSTR storeID;
    CComVariant vStore;
    CComPtr<IDispatch> pItemDisp;
    CComQIPtr<Outlook::_MailItem> pMailItem;

    hr = pStore->get_StoreID( &storeID );

    vStore = storeID;

    hr = pNameSpace->GetItemFromID( bstrEntryID, vStore, &pItemDisp); 

    pMailItem = pItemDisp;

    if(pMailItem)
    hr = pMailItem->Display();
    }
    }
    }

    pMailItem is my mail object.

    Thursday, July 23, 2015 3:24 PM
  • If what you are saying is that after modifying a message you see that message being uploaded to the IMAP server then it is not a duplication.  IMAP is just keeping its folders in sync with what you have changed.

    Thursday, July 23, 2015 6:39 PM
  • Yeah thanks for your reply,

    but as i said my client requirement is to see modified body with Footer attached.

    like:

    ________________________________

    (Logo) Some message

    ________________________________


    How can i achieve that? 

    Friday, July 24, 2015 5:56 AM
  • its strange not happening with outlook 2013

    does i need to logon first using username and password? ( for outlook 2007 & 2010 )

    Friday, July 24, 2015 6:18 AM
  • Outlook 2010 has to be connected to the IMAP server in order for it to sync folders.  If it isn't configured to provide the username and password automatically then it will have to be done manually.

    As far as behavioral differences between the various Outlook versions are concerned, have you verified that they are all configured in a similar manner?  For example, are all set to logon automatically?  Do all download complete messages and attachments?  I believe that Outlook 2013 always downloads complete items from IMAP servers



    • Edited by RLWA32 Friday, July 24, 2015 10:01 AM
    Friday, July 24, 2015 9:37 AM
  • r u sure if i login automatically when outlook starts, the modified mails will not get uploaded to server?
    Friday, July 24, 2015 10:43 AM
  • I never said that.
    Friday, July 24, 2015 10:50 AM
  • okk. but how to avoid,

    because its client requirement to modify mail body with logo and text as footer.

    and it should be get uploaded to server (or) any other solution?

    it is only happening with outlook 2007 & 2010. (not with 2013)


    Friday, July 24, 2015 10:56 AM
  • I am just stuck here, how can i avoid the saved mail should not upload to server?

    can anyone please help.


    Friday, July 24, 2015 12:26 PM
  • I'm not clear on what you want to accomplish.

    Question: Should modified mail be uploaded to the IMAP server?

    Please answer Yes or No.

    Friday, July 24, 2015 12:38 PM
  • NO

    Friday, July 24, 2015 12:41 PM
  • No need to SHOUT, I'm trying to help you.

    I don't think you can transparently accomplish what you want to do in an IMAP environment.

    Syncing folders is a standard IMAP behavior.

    You might be able to work around it with an ugly hack as follows:

    1. Retrieve the message.

    2. Disconnect from the IMAP server

    3. Edit the message as desired

    4. Move the message out of the IMAP inbox to a local folder not connected to the IMAP server.

    5. Reconnect to the IMAP server after the message has been moved out of the folders that get synced.

    • Edited by RLWA32 Friday, July 24, 2015 1:17 PM added hack idea
    Friday, July 24, 2015 12:53 PM
  • Hey i am really sorry, but this issue in on 2007 & 2010 but not with outlook 2013.

    Friday, July 24, 2015 1:20 PM
  • Are you saying that Outlook 2013 does not sync with the IMAP server to upload a changed message?
    Friday, July 24, 2015 1:55 PM
  • Yeah, that's strange behavior i observed, i can get mail body without fail, also even if i modified mail body/subject, same mail is not getting upload to server.
    Friday, July 24, 2015 2:05 PM
  • I just tested Outlook 2013 and Yahoo IMAP mail.  An item that I edited in the inbox was uploaded back up to the Yahoo IMAP server
    Friday, July 24, 2015 2:48 PM
  • You might be able to work around it with an ugly hack as follows:

    1. Retrieve the message.

    2. Disconnect from the IMAP server

    3. Edit the message as desired

    4. Move the message out of the IMAP inbox to a local folder not connected to the IMAP server.

    5. Reconnect to the IMAP server after the message has been moved out of the folders that get synced.



    But if we reconnect to IMAP server, the folder sync up will happen and will get uploaded.

    correct me if i am wrong.
    Saturday, July 25, 2015 7:51 AM
  • Thats why in step 4 above you move the message out of the IMAP folder into a local folder that won't be synced by IMAP.  Do you think your client will be happy with the connect/reconnect sequence happening with every message received?  It might not even work when multiple messages arrive at once.

    Like I said, it's a hack.  Your client' requirement is contrary to the way that IMAP works. Maybe they would be willing to use a different protocol that better supports their requirements

    Saturday, July 25, 2015 9:53 AM
  • Hey many thanks RLWA32.

    even great learning.., i will get back after discussion with my client.

    Saturday, July 25, 2015 10:50 AM
  • Take a look at how-to-avoid-mail-read-status-sync-with-mapi-server-programmatically?

    It talks about how IMAP syncing is unavoidable.

    Best of luck with your client discussions.


    • Marked as answer by rsquareshelke Monday, July 27, 2015 5:58 AM
    Saturday, July 25, 2015 11:53 AM
  • Yeah.. it's cleared now.. let me see what would be the decision.

    many thanks


    Monday, July 27, 2015 5:58 AM