Solved

simple MAPI question

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now