Solved

simple MAPI question

Posted on 2000-03-13
5
362 Views
Last Modified: 2008-02-26
I Use simple MAPI to send email,but
when I run MAPISendMail and outlook close the mail goes to the outbox and don't being sent until I open Outlook.
Is there some way to send it immediately?
0
Comment
Question by:peter_sh
5 Comments
 
LVL 4

Expert Comment

by:inpras
ID: 2615644
And how RU trying to send it?
Pl put some code here....
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2616230
tell us what are you using and give us some code
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2617155
Outlook must start immidiatly after
setting mail in outbox.
1. Test you profile
2. Try use MAPI_FORCE_DOWNLOAD mode in MAPILogon function

0
 

Author Comment

by:peter_sh
ID: 2622472
this is the code :

bool send_mail(char * DefaultProfile,char *fromDisplayName,
                     char *fromAddress,int recipients, char ** toDisplayName,char **toAddress,
                     char * subject , char * text,int attachments,char ** attachmentFullPath,char ** attachmentFilename )
{
            // Send a mail message containing a file and prompt for
            // recipients, subject, and note text.

            ULONG err;
            MapiFileDesc **attachmentArray  = (MapiFileDesc **)malloc(sizeof(MapiFileDesc *)*attachments);
            for (int index = 0; index < attachments ; index ++)
            {
                  MapiFileDesc attachment = {0,         // ulReserved, must be 0
                                                   0,         // no flags; this is a data file
                                                   (ULONG)-1, // position not specified
                                                   attachmentFullPath[index],  // pathname
                                                   attachmentFilename[index] ,      // original filename
                                                   NULL};               // MapiFileTagExt unused
                  attachmentArray[index] = &attachment;
            }      
            char ident_sr[20] = "sender";
            char ident_rec[20] = "reciever";
            char from[MAX_PATH] = "SMTP:";
            strcat(from,fromAddress);
            MapiRecipDesc sender = {0,                  // ulReserved, must be 0
                                                MAPI_ORIG, //Indicates the original sender of the message.  
                                                fromDisplayName, //Pointer to the display name
                                                from,  // address
                                                20,            // size of opaque entry identifier
                                                ident_sr};                        // opaque entry identifier
            MapiRecipDesc **recievers = (MapiRecipDesc**)malloc(sizeof(MapiRecipDesc*)*recipients);
            char to[MAX_PATH];
            for ( index = 0 ; index < recipients ; index ++ )
            {
                  strcpy(to,"SMTP:");
                  strcat(to,toAddress[index]);
                  MapiRecipDesc reciever = {0,                  // ulReserved, must be 0
                                                      MAPI_TO,            //Indicates the original sender of the message.  
                                                      toDisplayName[index], //Pointer to the display name
                                                      to,  // address
                                                      20,            // size of opaque entry identifier
                                                      ident_rec};                        // opaque entry identifier
                  recievers[index] = &reciever;
            }
            MapiMessage note = {0,            // reserved, must be 0
                                          subject,         //  subject
                                          text ,         //  note text
                                          NULL,         // NULL = interpersonal message
                                          NULL,         // no date; MAPISendMail ignores it
                                          NULL,         // no conversation ID
                                          MAPI_RECEIPT_REQUESTED  , // no flags, MAPISendMail ignores it
                                          &sender,         // originator
                                          recipients,            //  recipients
                                          *recievers ,         // recipients array
                                          attachments,            // attachment
                                          *attachmentArray}; // the attachment structure
 
      
            
            HINSTANCE hlibMAPI = LoadLibrary ( "MAPI32.DLL" );
          LPMAPISENDMAIL m_MAPISendMail = (LPMAPISENDMAIL)GetProcAddress(hlibMAPI,
                                                       "MAPISendMail");

            LHANDLE m_lhSession;
            LPMAPILOGON m_MAPILogon = (LPMAPILOGON)GetProcAddress(hlibMAPI,
                                                                 "MAPILogon");
       // Call the function through the function pointer.
         err = m_MAPILogon ( 0L, // Handle to parent window or 0.
                                 DefaultProfile,//"Microsoft Outlook", // Default profile name to use for MAPI session.
                               NULL, // Profile password for MAPI session.
                               MAPI_FORCE_DOWNLOAD  , // Various session settings. Can be 0
                               0L, // Reserved.  Must be 0L.
                               &m_lhSession ); // Handle to Simple MAPI session.

            err = m_MAPISendMail (m_lhSession,          // use implicit session.
                                          0L,          // ulUIParam; 0 is always valid
                                          &note,       // the message being sent
                                          0L,//MAPI_LOGON_UI  , // allow the user to edit the message
                                          0L                        // reserved; must be 0
                                           );          
            if (err != SUCCESS_SUCCESS )
            {
                  MessageBox(NULL,"Unable to send the message",NULL,MB_OK);
                  return false;
            }

            return true;
}
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 100 total points
ID: 2637380
Hi, i tesyed you code, very good, but i have some comments:
1. Main error: you need make MAPILogoff
in end of programm: without this Outlook don't start.
2. Best begin:  test, if MAPI installed
3. Better use ResolveNames API for
using Address Book.

All this you can fine in
http://support.microsoft.com/support/kb/articles/q171/0/96.asp

Good Luck. Alex
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

831 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