[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

OnFileSendMail in MDI application

Posted on 2000-02-28
8
Medium Priority
?
803 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 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