Markus
Markus

Reputation: 1482

Java: Open default mail client

I have a software that periodically parses my mail inbox. The functionallity of the program depends on the default mail program running.

How can I start the default mail program from within java?

I know that you can acheive this by using the Desktop class:

Desktop.getDesktop().mail()

but in addition to starting the default mail client it also opens a new email window which I don't want.
How do I open the default mail client without opening a "Compose a new EMail" window?

Edit: I'm trying to extract the information myselve now using this code snippet: http://support.microsoft.com/kb/180233/en-us but since this code doesn't compile (like most of the microsoft code snippets, which is really bad when you aren't a C++ developer and just need some code) because it's missing the reference to &lpProfileTable. How would the missing code look like?

Upvotes: 1

Views: 310

Answers (1)

mavroprovato
mavroprovato

Reputation: 8362

Here is how the MSDN Sample should look like:

#define UNICODE
#define _UNICODE
#define STRICT

#include <windows.h>
#include <mapix.h>

#include <iostream>

int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
                   LPSTR lpCmdLine, int nShowCmd) {
    // Get a IProfAdmin Interface.
    LPPROFADMIN lpProfAdmin;
    HRESULT hr = MAPIAdminProfiles(0, &lpProfAdmin);

    // Get the Table of Profiles
    LPMAPITABLE lpProfileTable;
    hr = lpProfAdmin->GetProfileTable(0, &lpProfileTable);

    // Build a restriction where PR_DEFAULT_PROFILE = TRUE
    SPropValue spvDefaultProfile;
    spvDefaultProfile.ulPropTag = PR_DEFAULT_PROFILE;
    spvDefaultProfile.Value.b = TRUE;

    SRestriction sres;
    sres.rt = RES_PROPERTY;
    sres.res.resProperty.relop = RELOP_EQ;
    sres.res.resProperty.ulPropTag = PR_DEFAULT_PROFILE;
    sres.res.resProperty.lpProp = &spvDefaultProfile;

    hr = lpProfileTable->Restrict(&sres, TBL_BATCH);
    hr = lpProfileTable->FindRow(&sres, BOOKMARK_BEGINNING, 0);

    LPSRowSet pRow = NULL;
    hr = lpProfileTable->QueryRows(1, 0, &pRow);
     // We have a match
    if (SUCCEEDED(hr)) {
        LPSTR lpDisplayName = pRow->aRow[0].lpProps[0].Value.lpszA;
        std::cout << lpDisplayName;
    }
}

It compiles under g++, but I cannot figure out how to link the executable...

Upvotes: 1

Related Questions