sendemail3

所属分类:网络编程
开发工具:Visual C++
文件大小:56KB
下载次数:43
上传日期:2006-07-22 15:28:28
上 传 者lndy97
说明:  这时一个很不错的关于发送邮件界面的一个小程序,采用VC++编写,很值得研究
(a very good time on the mail interface of a small program used to prepare VC, is worth studying)

文件列表:
send_email2 (0, 2003-05-12)
send_email2\SendEmail.html (21078, 2003-05-06)
send_email2\SendEmail.jpg (46781, 2003-05-06)
send_email2\Source (0, 2003-05-12)
send_email2\Source\res (0, 2003-05-12)
send_email2\Source\Resource.h (1100, 2003-04-22)
send_email2\Source\res\SendEMail.ico (1078, 2003-04-22)
send_email2\Source\res\SendEMail.rc2 (401, 2003-04-22)
send_email2\Source\SendEMail.clw (1712, 2003-04-23)
send_email2\Source\SendEMail.cpp (1310, 2003-04-22)
send_email2\Source\SendEMail.dsp (4277, 2003-04-22)
send_email2\Source\SendEMail.dsw (541, 2003-04-22)
send_email2\Source\SendEMail.h (1357, 2003-04-22)
send_email2\Source\SendEmail.html (21078, 2003-04-23)
send_email2\Source\SendEMail.rc (6387, 2003-04-23)
send_email2\Source\SendEMailDlg.cpp (8801, 2003-05-12)
send_email2\Source\SendEMailDlg.h (1572, 2003-04-22)
send_email2\Source\StdAfx.cpp (211, 2003-04-22)
send_email2\Source\StdAfx.h (1054, 2003-04-22)
send_email2\Source\调用默认的电子邮件程序发送EMail.txt (3006, 2003-04-23)

调用默认的电子邮件程序发送EMail 作者:耿海增 Email:genghaizeng@163.com 很多时候大家需要在程序中发送邮件,自己编又太麻烦,怎么办,呵呵,有现成的! 1、想省事儿的,用ShellExecute函数: ShellExecute(NULL,NULL,"mailto:email@163.net",NULL,NULL,SW_SHOW); 2、如果想自己多处理一些东西的话,比如加上默认的帐号、密码、附件等,就可以调用系统的Mapi函数。具体的用法大家可以去查MSDN都是以MAPI开头的,如MAPILogon、MAPISendMail等。下面演示如何调用默认的邮件程序发送邮件, 可以添加多个附件 //必须包括 mapi.h 头文件 #include "mapi.h" /********************************************************************* * 函数名称:CSendEMailDlg::OnSendMapi * 说明: 调用MAPI函数发送邮件。 * 作者: Geng * 时间 : 2003-04-22 20:08:30 *********************************************************************/ void CSendEMailDlg::OnSendMapi() { UpdateData(true); //装入MAPI32.DLL动态库 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; } int nFileCount = m_list.GetCount(); //有多少个附件需要发送 //分配内存保存附件信息 不能使用静态数组,因为不知道要发送附件的个数 MapiFileDesc* pFileDesc = (MapiFileDesc*)malloc(sizeof(MapiFileDesc) * nFileCount); memset(pFileDesc,0,sizeof(MapiFileDesc) * nFileCount); //分配内存保存附件文件路径 TCHAR* pTchPath = (TCHAR*)malloc(MAX_PATH * nFileCount); CString szText; for(int i = 0;i < nFileCount;i++) { TCHAR* p = pTchPath + MAX_PATH * i; m_list.GetText(i,szText); strcpy(p,szText); (pFileDesc + i)->nPosition = (ULONG)-1; (pFileDesc + i)->lpszPathName = p; (pFileDesc + i)->lpszFileName = p; } //收件人结构信息 MapiRecipDesc recip; memset(&recip,0,sizeof(MapiRecipDesc)); recip.lpszAddress = m_szEmailMAPI.GetBuffer(0); recip.ulRecipClass = MAPI_TO; //邮件结构信息 MapiMessage message; memset(&message, 0, sizeof(message)); message.nFileCount = nFileCount; //文件个数 message.lpFiles = pFileDesc; //文件信息 message.nRecipCount = 1; //收件人个数 message.lpRecips = &recip; //收件人 message.lpszSubject = m_szSubject.GetBuffer(0); //主题 message.lpszNoteText= m_szText.GetBuffer(0); //正文内容 //保存本程序窗口指针,因为发完邮件后要返回本程序的窗口 CWnd* pParentWnd = CWnd::GetSafeOwner(NULL, NULL); //发送邮件 int nError = lpfnSendMail(0, 0, &message, MAPI_LOGON_UI|MAPI_DIALOG, 0); if (nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE) { AfxMessageBox(AFX_IDP_FAILED_MAPI_SEND); } //返回程序 pParentWnd->SetActiveWindow(); //不要忘了释放分配的内存 free(pFileDesc); free(pTchPath); FreeLibrary(hMod); }

近期下载者

相关文件


收藏者