Solved

OnFileSendMail in MDI application

Posted on 2000-02-28
8
697 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
  • 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
 

Expert Comment

by:Stevex2
ID: 2569918
m_message is declared as a MapiMessage
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 45
Whole sheet autoscrub still needed 19 44
if loop in java 3 114
has22 challenge 11 72
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

762 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now