![](/img/trans.png)
[英]How to open default mail client(for e.g outlook) with attachment in java
[英]Java: Open default mail client
我有一个定期解析我的收件箱的软件。 程序的功能取决于运行的默认邮件程序。
如何从Java中启动默认邮件程序?
我知道您可以通过使用Desktop
类来实现此目的:
Desktop.getDesktop().mail()
但是除了启动默认的邮件客户端外,它还会打开一个我不需要的新电子邮件窗口。
如何在不打开“撰写新电子邮件”窗口的情况下打开默认邮件客户端?
编辑:我现在尝试使用以下代码片段自行提取信息: http : //support.microsoft.com/kb/180233/zh-cn,但由于此代码无法编译(像大多数的Microsoft代码片段一样) ,当您不是C ++开发人员,只需要一些代码时,这真的很糟糕),因为它缺少对&lpProfileTable
的引用。 丢失的代码将如何显示?
这是MSDN示例的外观:
#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;
}
}
它在g ++下编译,但是我不知道如何链接可执行文件...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.