Click here to Skip to main content
16,005,734 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Dialog tab order Pin
Michael Dunn7-Oct-06 7:59
sitebuilderMichael Dunn7-Oct-06 7:59 
AnswerRe: Dialog tab order Pin
Mark Salsbery7-Oct-06 8:15
Mark Salsbery7-Oct-06 8:15 
QuestionHow do I change icon and small icon for a windows class Pin
scody7-Oct-06 3:17
scody7-Oct-06 3:17 
AnswerRe: How do I change icon and small icon for a windows class Pin
Hamid_RT7-Oct-06 3:36
Hamid_RT7-Oct-06 3:36 
QuestionRe: How do I change icon and small icon for a windows class Pin
scody7-Oct-06 9:20
scody7-Oct-06 9:20 
AnswerRe: How do I change icon and small icon for a windows class Pin
Waldermort7-Oct-06 4:25
Waldermort7-Oct-06 4:25 
AnswerRe: How do I change icon and small icon for a windows class Pin
Mark Salsbery7-Oct-06 8:31
Mark Salsbery7-Oct-06 8:31 
QuestionSimple MAPI Error !!! Pin
Vinod Sankaranarayanan7-Oct-06 3:07
Vinod Sankaranarayanan7-Oct-06 3:07 
Hello,

I want to send mails(with attachments) from my MDI based application.

I got lot of articles from CodeProject regarding MAPI. I choose "David Brooks" article which uses simple MAPI.

Here is my code ...

class CSendFileTo
{

protected:

HWND m_hWndParnt; // Window handle
enum Error {SUCCESS, NO_ATTACHMENT=0x1001, NOT_A_WINDOW, LIB_LOAD_FAILED, GETPROC_FAILED};


// MAPI related data members
HINSTANCE hMAPI;






public:


CSendFileTo();
virtual ~CSendFileTo();

CSendFileTo(HWND hWnd)
{
m_hWndParnt = hWnd;
}



unsigned int SendMail(CString const &strAttachmentFileName,CString const &strSubject=_T(""),CString const &strToAddr=_T(""),CString const &strToName=_T(""),CString const &strBody=_T(""))
{
if (strAttachmentFileName.IsEmpty())
return NO_ATTACHMENT;

if (!m_hWndParnt || !::IsWindow(m_hWndParnt))
return NOT_A_WINDOW;

hMAPI = ::LoadLibraryA(_T("MAPI32.DLL"));
if (!hMAPI)
return LIB_LOAD_FAILED;

ULONG (PASCAL *SendMail)(ULONG, HWND, MapiMessage*, FLAGS, ULONG);
(FARPROC&)SendMail = GetProcAddress(hMAPI, _T("MAPISendMail"));

if (!SendMail)
{
::FreeLibrary(hMAPI);
return GETPROC_FAILED;
}

TCHAR szFileName[_MAX_PATH];
TCHAR szPath[_MAX_PATH];
TCHAR szSubject[_MAX_PATH];
TCHAR szBody[_MAX_PATH];
TCHAR szToName[_MAX_PATH];
TCHAR szToAddr[_MAX_PATH];

strcpy(szFileName, (LPCTSTR)strAttachmentFileName);
strcpy(szPath, (LPCTSTR)strAttachmentFileName);
strcpy(szSubject, (LPCTSTR)strSubject);
strcpy(szBody, (LPCTSTR)strBody);
strcpy(szToAddr, (LPCTSTR)strToAddr);
strcpy(szToName, (LPCTSTR)strToName);

// Setting Attachment Info
MapiFileDesc fileDesc;
ZeroMemory(&fileDesc, sizeof(fileDesc));
fileDesc.nPosition = (ULONG)-1;
fileDesc.lpszPathName = szPath;
fileDesc.lpszFileName = PathFindFileName(szFileName); // Remove the path

// Setting Recepient Info
MapiRecipDesc recpnts;
ZeroMemory(&recpnts, sizeof(recpnts));
recpnts.ulReserved =0;
recpnts.ulRecipClass = 1;
recpnts.lpszName = szToName;
recpnts.lpszAddress = szToAddr;

//Setting the Message Info
MapiMessage message;
ZeroMemory(&message, sizeof(message));
message.lpszSubject = szSubject;
message.nFileCount = 1;
message.nRecipCount = 1;
message.lpszNoteText = szBody;
message.lpRecips = &recpnts;
message.lpFiles = &fileDesc;




int nError = SendMail(0,m_hWndParnt, &message, MAPI_LOGON_UI|MAPI_DIALOG, 0);

if (nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
return nError;

::FreeLibrary(hMAPI); // Freeing the DLL handle

return SUCCESS;
}


void ShowError(UINT errCod)
{
if (errCod)
{
CString str;
str.Format("Error: %X", errCod);
AfxMessageBox(str);
}
}





};

// Invoking Send Mail function
void CDefectLinkerDlg::OnButtonSend()
{

CSendFileTo sendTo(this->m_hWnd);
int nError = sendTo.SendMail(m_attachments,strSubject,strURL,strName,strBody);

if(nError != 0)
{
sendTo.ShowError(nError);
}
}

I can run this application. I got the MS Outlook 2000 window and it shows my mail with attachment.

But when I press the "Send" button in Outlook , both my application and the MS
Outlook program is closed.


But that mail is located in my Outbox. But Outlook cannot deliver that meesage ..,I got "Mail delivery failure" error...!



What will be the problem ?

Pls help me...

Thanks in advance

vinsankar

AnswerRe: Simple MAPI Error !!! Pin
Hamid_RT7-Oct-06 4:10
Hamid_RT7-Oct-06 4:10 
GeneralRe: Simple MAPI Error !!! Pin
Vinod Sankaranarayanan7-Oct-06 4:26
Vinod Sankaranarayanan7-Oct-06 4:26 
GeneralRe: Simple MAPI Error !!! Pin
Hamid_RT7-Oct-06 6:53
Hamid_RT7-Oct-06 6:53 
GeneralRe: Simple MAPI Error !!! Pin
Hamid_RT19-Oct-06 7:54
Hamid_RT19-Oct-06 7:54 
GeneralRe: Simple MAPI Error !!! Pin
Vinod Sankaranarayanan20-Oct-06 4:12
Vinod Sankaranarayanan20-Oct-06 4:12 
GeneralRe: Simple MAPI Error !!! Pin
Hamid_RT20-Oct-06 6:47
Hamid_RT20-Oct-06 6:47 
QuestionInternet Settings Pin
Benlahrech .Dj7-Oct-06 2:22
Benlahrech .Dj7-Oct-06 2:22 
Questionincludeing class in dll Pin
Sarguna Reddiar7-Oct-06 1:32
Sarguna Reddiar7-Oct-06 1:32 
Questionmore information Pin
Sarguna Reddiar7-Oct-06 1:34
Sarguna Reddiar7-Oct-06 1:34 
AnswerRe: includeing class in dll Pin
Hamid_RT7-Oct-06 2:55
Hamid_RT7-Oct-06 2:55 
Questiongray item in context menu Pin
zon_cpp6-Oct-06 23:25
zon_cpp6-Oct-06 23:25 
AnswerRe: gray item in context menu Pin
Hamid_RT7-Oct-06 2:31
Hamid_RT7-Oct-06 2:31 
AnswerRe: gray item in context menu Pin
Michael Dunn7-Oct-06 8:02
sitebuilderMichael Dunn7-Oct-06 8:02 
GeneralRe: gray item in context menu Pin
zon_cpp7-Oct-06 22:02
zon_cpp7-Oct-06 22:02 
QuestionWhat wrong with my code ? Pin
Yanshof6-Oct-06 23:05
Yanshof6-Oct-06 23:05 
AnswerRe: What wrong with my code ? Pin
_AnsHUMAN_ 6-Oct-06 23:19
_AnsHUMAN_ 6-Oct-06 23:19 
AnswerRe: What wrong with my code ? Pin
raghuji.rao7-Oct-06 1:29
raghuji.rao7-Oct-06 1:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.