The MAPISendMail function sends a standard message.SyntaxMAPISendMail(
Session as Long,.
UIParam as Long, 
Message as MapiMessage, 
Recips as MapiRecip, 
Files as MapiFile, 
Flags as Long,
Reserved as Long) as LongParametersSessionInput parameter specifying either a session handle that represents a Simple MAPI session or zero. If the Session parameter is zero, MAPI logs on the user and creates a session that exists only for the duration of the call. The temporary session may be an existing shared session or a new one. If necessary, a logon dialog box is displayed. UIParamThe parent window handle for the dialog box. A value of zero specifies that any dialog box displayed is application modal.MessageInput parameter specifying the message to be sent. An empty string indicates no text. Each paragraph should be terminated with either a carriage return (0x0d), a line feed (0x0a), or a carriage return-line feed pair (0x0d0a). The implementation wraps lines as appropriate. Implementations may place limits on the size of the text. The MAPI_E_TEXT_TOO_LARGE value is returned if this limit is exceeded. Client applications can set MAPI_RECEIPT_REQUESTED in the Flags member to ask for a read report.RecipsInput parameter specifying the first element of an array of recipients. When the RecipCount field in the Message parameter is zero, this parameter is ignored. The Recips parameter can include either an entry identifier, the recipient's name, an address, or a name and address pair. Depending on the type and amount of information passed, MAPISendMail will perform varied levels of name resolution. If an entry identifier in the EntryID field is specified, the MAPISendMail function performs no lookup and ignores the name and address. If only a name is specified, MAPISendMail resolves the name to a valid address using name resolution rules defined by Simple MAPI. If only an address is specified, MAPISendMail uses this address for both message delivery and for displaying the recipient name; no name resolution occurs. If both a name and address are specified, again the MAPISendMail function does not resolve the name. The specified name is used as the display name and not for resolution. FilesInput parameter specifying the first element of an array of attachment files written when the message is read. The number of attachments per message might be limited in some systems. If the limit is exceeded, the message MAPI_E_TOO_MANY_FILES is returned. When the FileCount field in the MapiMessage type pointed to by the Message
 parameter is zero, this parameter is ignored. Attachment files are read and attached to the message before the call returns. Do not attempt to display attachments outside the range of the message body.FlagsInput parameter specifying a bitmask of option flags. The following flags can be set:MAPI_DIALOGIndicates that a dialog box should be displayed to prompt the user for recipients and other sending options. Set the MAPI_LOGON_UI flag if the function should display a dialog box to prompt for log on. When this flag is not set, the function does not display a dialog box and returns a message if the user is not signed in.MAPI_LOGON_UIIndicates that a dialog box should be displayed to prompt for logon if required. When the MAPI_LOGON_UI flag is not set, the application does not display a logon dialog box and returns an error if the user is not logged on. MAPISaveMail ignores this flag if the MessageID parameter is empty.MAPI_NEW_SESSIONIndicates an attempt should be made to create a new session rather than acquire the environment's shared session.  If the MAPI_NEW_SESSION flag is not set, the function uses an existing shared session.ReservedReserved for future use; must be zero.Return ValuesThe possible return values for the MAPISendMail function and their meanings are as follows:MAPI_E_AMBIGUOUS_RECIPIENTA recipient matched more than one of the recipient descriptor structures and MAPI_DIALOG was not set. No message was sent.MAPI_E_ATTACHMENT_NOT_FOUNDThe specified attachment was not found; no message was sent.MAPI_E_ATTACHMENT_OPEN_FAILUREThe specified attachment could not be open; no message was sent.MAPI_E_BAD_RECIPTYPEThe type of a recipient was not MAPI_TO, MAPI_CC, or MAPI_BCC. No message was sent.MAPI_E_FAILUREOne or more unspecified errors occurred; no message was sent.MAPI_E_INSUFFICIENT_MEMORYThere was insufficient memory to proceed. No message was sent.MAPI_E_LOGIN_FAILUREThere was no default logon, and the user failed to log on successfully when the logon dialog box was displayed. No message was sent.MAPI_E_TEXT_TOO_LARGEThe text in the message was too large to sent; the message was not sent.MAPI_E_TOO_MANY_FILESThere were too many file attachments; no message was sent.MAPI_E_TOO_MANY_RECIPIENTSThere were too many recipients; no message was sent.MAPI_E_UNKNOWN_RECIPIENTA recipient did not appear in the address list; no message was sent.MAPI_E_USER_ABORTThe user canceled the process; no message was sent.SUCCESS_SUCCESSMAPISendMail successfully sent the message.CommentsMAPISendMail sends a standard message, with or without any user interaction. If recipient names, file attachments, or message text are provided, the MAPISendMail function can send the files or note without prompting users. If the optional parameters are specified and a dialog box is requested by use of the MAPI_DIALOG flag, the parameters provide the initial values for the dialog box.
File attachments are copied to the message before the function returns; therefore, later changes to the files do not affect the contents of the message. The files must be closed when they are copied.The Visual Basic MAPISendMail function takes the recipients and file attachments from the Recips and Files parameters, which should each be the first element of dynamically allocated arrays of their respective types. These arrays are not redimensioned.
All strings must be specified in the current character set or code page of your application's operating system process.

解决方案 »

  1.   

    我做的程序里正好有个调用outlook发送html格式的邮件的例子, 
    <br />
     
    希望对你有帮助! 
    <br />
     
    procedure  TPPMS120.sptnSendClick(Sender:  TObject); 
    <br />
     
    const  olMailItem  =  0; 
    <br />
     
    var  Outlook,MailItem,Recipient:  variant; 
    <br />
     
            strFilename,strTemp,strTempDir:string; 
    <br />
     
            strlstAddr:Tstringlist; 
    <br />
     
            i:integer; 
    <br />
     
    begin 
    <br />
     
        try 
    <br />
     
            Outlook  :=  CreateOleObject('Outlook.Application'); 
    <br />
     
        except 
    <br />
     
            Outlook  :=  GetActiveOleObject('Outlook.Application'); 
    <br />
     
        end; 
    <br />
     
        MailItem  :=  Outlook.CreateItem(olMailItem); 
    <br />
     
        strTempDir:='C:\temp'+  formatdatetime('YYYYMMDDHHMMSS',Now); 
    <br />
     
        CreateDir(strTempDir); 
    <br />
     
        strlstAddr:=Tstringlist.Create; 
    <br />
     
        try 
    <br />
     
            GetAddrList('TO',strlstAddr); 
    <br />
     
            for  i:=0  to  strlstAddr.Count-1  do 
    <br />
     
            begin 
    <br />
     
                Recipient:=MailItem.Recipients.Add(strlstAddr[i]); 
    <br />
     
                Recipient.type:=olTO; 
    <br />
     
                if  not  Recipient.resolve  then 
    <br />
     
                    break; 
    <br />
     
            end; 
    <br />
     
            GetAddrList('CC',strlstAddr); 
    <br />
     
            for  i:=0  to  strlstAddr.Count-1  do 
    <br />
     
            begin 
    <br />
     
                Recipient:=MailItem.Recipients.Add(strlstAddr[i]); 
    <br />
     
                Recipient.type:=olCC; 
    <br />
     
                if  not  Recipient.resolve  then 
    <br />
     
                    break; 
    <br />
     
            end; 
    <br />
     
            MailItem.Subject  :='Booking  result  as  of  '+strFileName; 
    <br />
     
            GetMailBodyHtml(strTemp); 
    <br />
     
            MailItem.htmlBody  :=strTemp; 
    <br />
     
            MakeAttachFile(strTempDir+'\'+strFileName+'.xls'); 
    <br />
     
            MailItem.Attachments.Add(strTempDir+'\'+strFileName+'.xls'); 
    <br />
     
            //mailitem.display; 
    <br />
     
            mailitem.send; 
    <br />
     
        finally 
    <br />
     
            strlstAddr.free; 
    <br />
     
            MailItem:=Unassigned; 
    <br />
     
            Recipient:=Unassigned; 
    <br />
     
            //outlook.quit; 
    <br />
     
            outlook:=Unassigned; 
    <br />
     
            DeleteTempDir(strTempDir,strFileName); 
    <br />
     
        end; 
    <br />
     
    end; 
    <br />