none
MAPISendMail to Outlook RRS feed

  • Question

  • We have an application that uses MAPI to send mail.  It works fine with every email client we have tried except Outlook.  With Outlook the dialog appears asking if you want to allow or deny.  If you click on allow, nothing happens.

    (*lpfnMAPILogon)(0, NULL, NULL, MAPI_NEW_SESSION | MAPI_LOGON_UI , 0,&lhSession);  

    Tried various combinations of flags with no result. 

    • Moved by Helen Zhao Monday, May 21, 2012 3:00 AM (From:Visual C++ General)
    Saturday, May 19, 2012 9:40 AM

Answers

All replies

  • Hi grensofy,

    According to your description, I'd like to move your thread to "Outlook for Developers" for better support where more experts live.

    Thank you for your understanding.
    Best regards,


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us

    Monday, May 21, 2012 2:59 AM
  • Hi grensoft,

    Thanks for posting in the MSDN Forum.

    I will involve some experts into this issue to see whether they can help you out. There might be sometime delay, appreciate for you patience.

    Have a good day,

    Tom 


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, May 22, 2012 6:00 AM
    Moderator
  • What version of Outlook are you testing with and what version of Windows? Your code snippet only shows MAPILogon and doesn't show your MAPISendMail call...could you show the code doing MAPISendMail? Are you checking for error returns from MAPISendMail? Also (and I know this sounds odd) is your Anti-Virus up to date?
    Tuesday, May 22, 2012 8:21 PM
    Answerer
  • Thanks for your response.

    We are using Outlook 2010, Windows Vista Home Premium with SP1.  Our Anti-Virus is up to date.  Our clients experience the same problem when using our software with Outlook.

    Here is the code:

    // MAPI STUFF //////////////////
        LHANDLE lhSession;
        HMODULE hMAPILib;
        LPMAPILOGON lpfnMAPILogon;
        LPMAPISENDMAIL lpfnMAPISendMail;
        LPMAPILOGOFF lpfnMAPILogoff;
        ///////////////////////////////
        hMAPILib = LoadLibrary("MAPI32.DLL");
        if(hMAPILib==NULL){
            AfxMessageBox("MAPI32.DLL file not found");
            return;
        }

        MapiRecipDesc recipient =
        {
        0, MAPI_TO,
       
        "","SMTP:info@grensoft.com",
        0, NULL
        };

        MapiMessage message =
        {
        0,"Test",
        "Hello",
        NULL, NULL, NULL, 0, NULL, 1, &recipient, 0, NULL
        };


        lpfnMAPILogon =

            (LPMAPILOGON)GetProcAddress(hMAPILib, "MAPILogon");

        lpfnMAPISendMail =

            (LPMAPISENDMAIL)GetProcAddress(hMAPILib, "MAPISendMail");

        lpfnMAPILogoff =

            (LPMAPILOGOFF)GetProcAddress(hMAPILib, "MAPILogoff");

        (*lpfnMAPILogon)(0, NULL, NULL, MAPI_NEW_SESSION | MAPI_LOGON_UI , 0,&lhSession);    

        (*lpfnMAPISendMail)(lhSession, 0, &message, 0, 0);

        (*lpfnMAPILogoff)(lhSession, 0, 0, 0);
        
        FreeLibrary(hMAPILib);


    Dick

    Wednesday, May 23, 2012 7:37 AM
  • What happens if you remove the calls to Logon and Logoff and let MAPISendMail handle the session on it's own? Also, you need to catch the return value from MAPISendMail to see if you're getting an error, like this:

    ULONG ulError = (*lpfnMAPISendMail)(NULL, 0, &message, 0, 0);
    // Display ulError here
    

    I suspect you are getting an error here. Knowing what it is will help.

    Thursday, May 24, 2012 12:49 PM
    Answerer
  • If I remove the calls to Logon & Logoff nothing happens (neither with Outlook nor Eudora).

    With Outlook as the default email client the error codes are 2 if I click on Allow and 26 if I click on Deny.

    Don't know yet if I get an error with Eudora as Windows won't let me make it default again (there's a trick to it which I have forgotten).


    Dick

    Thursday, May 24, 2012 1:27 PM
  • Error code is 0 when Eudora is the default email client.

    Dick

    Thursday, May 24, 2012 2:02 PM
  • 2 is MAPI_E_FAILURE, and 26 is MAPI_E_NOT_SUPPORTED.

    I think this thread applies here for Outlook:

    http://ureader.com/msg/14751481.aspx

    You'll need to talk to Eudora folks for Eudora not working.

    Friday, June 1, 2012 2:51 AM
    Answerer
  • The MapiSendMail works fine with Eudora, Thunderbird, Pegasus, Outlook Express, Windows Mail, etc.  The only problem I'm having regarding Eudora is that after Outlook is made default mail client it is difficult to make Eudora the default again, it keeps changing back to Outlook even without running Outlook.  But that's a separate problem and nothing to worry about.

    The problem with Outlook is not restricted to Vista (which it seems to be in the thread mentioned in the last post), it occurs with all versions of Windows.

    Thanks,

    Richard


    Dick

    Friday, June 1, 2012 7:07 AM
  • What happens if you try passing a name in MapiRecipDesc? IE, instead of "", pass "Info".
    Tuesday, June 5, 2012 7:49 PM
    Answerer
  • That worked!

    Thank you so much.


    Dick

    Wednesday, June 6, 2012 7:27 AM