Solved

OnFileSendMail in MDI application

Posted on 2000-02-28
8
774 Views
Last Modified: 2013-11-20
How do I email my serialized CDocument-derived object as an email attachment ? I read OnFileSendMail() is supposed to do so, but it fails on the following line in docmapi.cpp (implementing CDocument::OnFileSendMail()):

int nError = lpfnSendMail(0, (ULONG)pParentWnd->GetSafeHwnd(),&message, MAPI_LOGON_UI|MAPI_DIALOG, 0);
 
witn nError=2. I am getting messages like:
"The form required to view this message cannot be displayed"(From Microsoft Exchange),
and then
"Send mail failed to send message" (from my app).

My VC code really does very little: I use default implementation for OnFileSendMail, and never change the modified flag for the document. So OnFileSendMail simply takes the original file from where the document was opened, and does not call any SaveDocument() functions.

For email, I am using MS Outlook.
0
Comment
Question by:olegsp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:cdesigner
ID: 2566532
Im use this code:
path - path to file with attachment or NULL

void SendMail(CString path)
{
    m_hInstMail = ::LoadLibrary("MAPI32.DLL");
   
    ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
    (FARPROC&)lpfnSendMail = GetProcAddress(m_hInstMail, "MAPISendMail");
    if (lpfnSendMail == NULL)
    {
        AfxMessageBox("MAPI: Inicialization error");
        ::FreeLibrary(m_hInstMail);
        return;
    }
   
    // prepare the file description (for the attachment)
    MapiFileDesc fileDesc;
    memset(&fileDesc, 0, sizeof(fileDesc));
    fileDesc.nPosition = (ULONG)-1;
    fileDesc.lpszPathName = path.LockBuffer();
    path.UnlockBuffer();
    // prepare the message (empty with 1 attachment)
    MapiMessage message;
    memset(&message, 0, sizeof(message));
    message.nFileCount = 1;
    message.lpFiles = &fileDesc;
    int nError = lpfnSendMail(0, (ULONG)NULL,&message, MAPI_LOGON_UI|MAPI_DIALOG, 0);
    if (nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
    {
        AfxMessageBox("MAPI: send message error");
    }
    ::FreeLibrary(m_hInstMail);
}
0
 
LVL 1

Author Comment

by:olegsp
ID: 2569824
Now my nError=12. I start to believe that some information is missing - do I also need to specify recipient's address or anything else ??? Or it is supposed to automaticall pop up Outlook email window ?
0
 

Expert Comment

by:Stevex2
ID: 2569914
Not Sure but heres some example code on my end

      m_message.lpFiles = (MapiFileDesc *) realloc(m_message.lpFiles, (m_message.nFileCount + 1) * sizeof(MapiFileDesc));
      memset(&m_message.lpFiles[m_message.nFileCount], 0, sizeof(MapiFileDesc));

      ASSERT(m_message.lpFiles);
      
      if (m_message.lpFiles == (MapiFileDesc *) NULL)
      {
            m_error = IMAPI_FAILATTACH;
            return FALSE;
      }

      m_message.lpFiles[m_message.nFileCount].lpszPathName = (LPTSTR) malloc(strlen(path) + 1);
      strcpy(m_message.lpFiles[m_message.nFileCount].lpszPathName, path);

      if (name != (LPCTSTR) NULL)
      {
            m_message.lpFiles[m_message.nFileCount].lpszFileName = (LPTSTR) malloc(strlen(name) + 1);
            strcpy(m_message.lpFiles[m_message.nFileCount].lpszFileName, name);
      }

      m_message.nFileCount++;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:Stevex2
ID: 2569918
m_message is declared as a MapiMessage
0
 
LVL 1

Author Comment

by:olegsp
ID: 2569947
Adjusted points to 200
0
 
LVL 5

Accepted Solution

by:
JohnCz earned 200 total points
ID: 2584413
It is not your program I think.
If you are experiencing the same trying to send e-mail from other programs, it looks like you are having problem with Exchange or Outlook.

This is happening sometimes when Frmcache.dat becomes corrupted.
The most efficient method is to remove client and reinstall it. Make sure that above mentioned file is removed or remove it yourself.

That should fix a problem.

If you are running Office 2000 try (after deleting all instances of Frmcache.dat).
On Help menu of any Office program, click Detect and Repair to fix a problem.
0
 
LVL 1

Author Comment

by:olegsp
ID: 2587782
Thank you, this helped.
0
 
LVL 5

Expert Comment

by:JohnCz
ID: 2588278
You are welcome
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question