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
Solved

simple MAPI question

Posted on 2000-03-13
5
364 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

792 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