Solved

OnFileSendMail in MDI application

Posted on 2000-02-28
8
730 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tab names are off by one 5 54
substring method in java 1 119
conditional code and condition difference 9 82
Hibernate methods 2 71
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

776 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