最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
在VC中调用默认的电子邮件程序发送邮件
时间:2022-06-30 11:35:29 编辑:袖梨 来源:一聚教程网
很多时候大家需要在程序中发送邮件,自己编又太麻烦,怎么办,呵呵,有现成的!
1、想省事儿的,用ShellExecute函数:
ShellExecute(NULL,NULL,"mailto:[email protected]",NULL,NULL,SW_SHOW);
2、如果想自己多处理一些东西的话,比如加上默认的帐号、密码、附件等,就可以调用系统的Mapi函数。具体的用法大家可以去查MSDN都是以MAPI开头的,如MAPILogon、MAPISendMail等。下面这段代码演示如何调用默认的邮件程序发送邮件。
#include "mapi.h"
void CTestMapiDlg::OnSendMail()
{
HMODULE hMod = LoadLibrary("MAPI32.DLL");
if (hMod == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD);
return;
}
ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
(FARPROC&)lpfnSendMail = GetProcAddress(hMod, "MAPISendMail");
if (lpfnSendMail == NULL)
{
AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL);
return;
}
ASSERT(lpfnSendMail != NULL);
TCHAR szPath[_MAX_PATH] = "C:Winntsetup.log";
TCHAR szTitle[_MAX_PATH] = "setup.log";
// prepare the file description (for the attachment)
MapiFileDesc fileDesc;
memset(&fileDesc, 0, sizeof(fileDesc));
fileDesc.nPosition = (ULONG)-1;
fileDesc.lpszPathName = szPath;
fileDesc.lpszFileName = szTitle;
// prepare the message (empty with 1 attachment)
MapiMessage message;
memset(&message, 0, sizeof(message));
message.nFileCount = 1;
message.lpFiles = &fileDesc;
int nError = lpfnSendMail(0, 0,
&message, MAPI_LOGON_UI¦MAPI_DIALOG, 0);
// after returning from the MAPISendMail call, the window must
// be re-enabled and focus returned to the frame to undo the workaround
// done before the MAPI call.
if (nError != SUCCESS_SUCCESS &&
nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_SEND);
}
}
1、想省事儿的,用ShellExecute函数:
ShellExecute(NULL,NULL,"mailto:[email protected]",NULL,NULL,SW_SHOW);
2、如果想自己多处理一些东西的话,比如加上默认的帐号、密码、附件等,就可以调用系统的Mapi函数。具体的用法大家可以去查MSDN都是以MAPI开头的,如MAPILogon、MAPISendMail等。下面这段代码演示如何调用默认的邮件程序发送邮件。
#include "mapi.h"
void CTestMapiDlg::OnSendMail()
{
HMODULE hMod = LoadLibrary("MAPI32.DLL");
if (hMod == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD);
return;
}
ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
(FARPROC&)lpfnSendMail = GetProcAddress(hMod, "MAPISendMail");
if (lpfnSendMail == NULL)
{
AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL);
return;
}
ASSERT(lpfnSendMail != NULL);
TCHAR szPath[_MAX_PATH] = "C:Winntsetup.log";
TCHAR szTitle[_MAX_PATH] = "setup.log";
// prepare the file description (for the attachment)
MapiFileDesc fileDesc;
memset(&fileDesc, 0, sizeof(fileDesc));
fileDesc.nPosition = (ULONG)-1;
fileDesc.lpszPathName = szPath;
fileDesc.lpszFileName = szTitle;
// prepare the message (empty with 1 attachment)
MapiMessage message;
memset(&message, 0, sizeof(message));
message.nFileCount = 1;
message.lpFiles = &fileDesc;
int nError = lpfnSendMail(0, 0,
&message, MAPI_LOGON_UI¦MAPI_DIALOG, 0);
// after returning from the MAPISendMail call, the window must
// be re-enabled and focus returned to the frame to undo the workaround
// done before the MAPI call.
if (nError != SUCCESS_SUCCESS &&
nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_SEND);
}
}
相关文章
- 无限暖暖搭乘大鸟巴士怎么玩 公测第三天每日任务做法介绍 12-27
- 奇迹暖暖绚光护佑搭配攻略 奇迹暖暖绚光护佑过关攻略 12-27
- 绝区零月城柳意像影画怎么样 12-27
- 无限暖暖翩翩愿飞去怎么样 12-27
- 黑神话悟空1.0.12.16581版本更新公告 12-27
- 光遇12.27红石碎片在哪里 12-27