?
Solved

OnFileSendMail in MDI application

Posted on 2000-02-28
8
Medium Priority
?
788 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:
Janusz Czopowik earned 800 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:Janusz Czopowik
ID: 2588278
You are welcome
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

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