News
 

DLLBinder Example - Send Email

Want to create your own version of Outlook? Or just add e-mail capabilities to your Director application?

This example gives the user the ability to send a e-mail to a list of recipients. You can also send multiple file attachments with the e-mail.

To use this code, make sure you have downloaded the DLLBinder or DLLBinder Pro and String Handler XTRAs. Then simply copy and paste the Lingo script below into Director.

Feel free to make use of this code in any way you want. If you make any great improvements, please send us a copy. Or if you have any other examples you would like to appear in these LIBRARY pages, please send it to info@the-mindseye.co.uk

Minds Eye Visualisation Services accepts no responibility for the reliability of any of the source code appearing in these pages. Use it at your own risk.

 

Requirements


DLLBinder or DLLBinder pro


Minds Eye String Handler

 

Download zip Download Zip file   (mevSendEmail.zip - 9Kb)


------------------------------------------------------------------------
------------------------------------------------------------------------
-- Name           SendEmail
-- Script Type    Parent 
-- Description    wrapper for the Win32 MAPISendMail function
-- Creation Date  31/10/2004
-- Author         Minds Eye Visualisation
------------------------------------------------------------------------
------------------------------------------------------------------------


--properties for the file attachments data structure lpMapiFileDesc
property m_strAttachmentsFormat
property
 m_lstAttachmentsArray
property
 m_nAttachCount

--properties for the recipients data structure lpMapiRecipDesc
property m_strRecipientsFormat
property
 m_lstRecipientsArray
property
 m_nRecipCount

--properties for the main message data structure lpMapiMessage
property m_strMapiMessageFormat
property
 m_lstMapiMessageData

--const EAPI details
property m_strDllName
property
 m_strFnName

--EAPI return value properties
property m_strRetValFormat
property
 m_lstRetVal

--mevString objects for the message subject and body text
property m_ostrSubject
property
 m_ostrBody


------------------------------------------------------------------------
------------------------------------------------------------------------
-- FUNCTION new
--
-- PURPOSE
--
-- new object initialisation
------------------------------------------------------------------------
------------------------------------------------------------------------
on new me
  
  --const EAPI details
  m_strDllName="mapi32.dll"
  m_strFnName="MAPISendMail"

  
  --EAPI return value properties
  m_strRetValFormat="D"
  m_lstRetVal=[]
  
  --default attachment property vals imply no attachments
  m_strAttachmentsFormat="r"
  
  return me

  
end


------------------------------------------------------------------------
------------------------------------------------------------------------
-- FUNCTION SetSubject
--
-- PURPOSE
--
-- assigns the object with the email subject
------------------------------------------------------------------------
------------------------------------------------------------------------
on SetSubject me, strSubject
  
  m_ostrSubject=new
(xtra "mevString", strSubject)
  
end


------------------------------------------------------------------------
------------------------------------------------------------------------
-- FUNCTION SetBody
--
-- PURPOSE
--
-- assigns the object with the email message body text
------------------------------------------------------------------------
------------------------------------------------------------------------
on SetBody me, strMessageBody
  
  m_ostrBody=new
(xtra "mevString", strMessageBody)
  
end


------------------------------------------------------------------------
------------------------------------------------------------------------
-- FUNCTION SetAttachments
--
-- PURPOSE
--
-- creates an array of file attachments according to the following MAPI 
-- data structure defined in mapi.h 
--
--  typedef struct 
--  { 
--    ULONG  ulReserved;      
--    ULONG  flFlags;      
--    ULONG  nPosition;           
--    LPTSTR lpszPathName;      
--    LPTSTR lpszFileName;      
--    LPVOID lpFileType;      
--  } MapiFileDesc, FAR *lpMapiFileDesc; 
--
------------------------------------------------------------------------
------------------------------------------------------------------------
on SetAttachments me, lstAttachmentPathNames
  
  m_lstAttachmentsArray=[]
  m_nAttachCount=lstAttachmentPathNames.count

  
  repeat with
 nNext=1 to m_nAttachCount
    
    nIndex=mevgRFindChar(lstAttachmentPathNames[nNext], 92
) + 1
    strFileName=mevgMid(lstAttachmentPathNames[nNext], nIndex, 128
)
    
    lstMapiFileDesc=[]
    lstMapiFileDesc[3
]=-1
    lstMapiFileDesc[4
]=lstAttachmentPathNames[nNext]
    lstMapiFileDesc[5
]=strFileName
    lstMapiFileDesc[6
]=0
    
    m_lstAttachmentsArray.append
(lstMapiFileDesc)
    
  end repeat

  
  m_strAttachmentsFormat="["
 & m_nAttachCount & "{D,D,D,s256,s128,D}]"  
  
end


------------------------------------------------------------------------
------------------------------------------------------------------------
-- FUNCTION SetRecipients
--
-- PURPOSE
--
-- creates an array of recipients according to the following MAPI data
-- structure defined in mapi.h
--
--  typedef struct
--  { 
--    ULONG  ulReserved           
--    ULONG  ulRecipClass;      
--    LPTSTR lpszName; 
--    LPTSTR lpszAddress;      
--    ULONG  ulEIDSize; 
--    LPVOID lpEntryID;      
--  } MapiRecipDesc, FAR *lpMapiRecipDesc; 
--
--  the following defines are all the valid values for the 
--  ulRecipClass member of the above structure -as defined in mapi.h
--
--  #define MAPI_ORIG   0 /* Recipient is message originator     */
--  #define MAPI_TO     1 /* Recipient is a primary recipient    */
--  #define MAPI_CC     2 /* Recipient is a copy recipient       */
--  #define MAPI_BCC    3 /* Recipient is blind copy recipient   */
--
------------------------------------------------------------------------
------------------------------------------------------------------------
on SetRecipients me, lstRecipients
  
  m_lstRecipientsArray=[]
  m_nRecipCount=lstRecipients.count

  
  repeat with
 nNext=1 to m_nRecipCount
    
    lstMapiRecipDesc=[]
    lstMapiRecipDesc[2
]=1 -- ie this Recipient is a primary recipient
    lstMapiRecipDesc[3]=lstRecipients[nNext]
    lstMapiRecipDesc[6
]=0
    
    m_lstRecipientsArray.append
(lstMapiRecipDesc)
    
  end repeat

  
  m_strRecipientsFormat="["
 & m_nRecipCount & "{D,D,s128,D,D,D}]"  
  
end


------------------------------------------------------------------------
------------------------------------------------------------------------
-- FUNCTION BuildMAPIMessageStruct
--
-- PURPOSE
--
-- creates a data structure for the following MAPI 
-- data structure defined in mapi.h 
--
--  typedef struct 
--  { 
--    ULONG ulReserved;      
--    LPTSTR lpszSubject;      
--    LPTSTR lpszNoteText;      
--    LPTSTR lpszMessageType; 
--    LPTSTR lpszDateReceived; 
--    LPTSTR lpszConversationID;      
--    FLAGS flFlags;      
--    lpMapiRecipDesc lpOriginator; 
--    ULONG nRecipCount;      
--    lpMapiRecipDesc lpRecips;      
--    ULONG nFileCount;      
--    lpMapiFileDesc lpFiles;           
--  } MapiMessage, FAR *lpMapiMessage; 
--
------------------------------------------------------------------------
------------------------------------------------------------------------
on BuildMAPIMessageStruct me
  
  m_strMapiMessageFormat=\
  "*{"
  &\
     "D,"
 &\
     "r,"
 &\
     "r,"
 &\
     "r,"
 &\
     "r,"
 &\
     "r,"
 &\
     "D,"
 &\
     "r,"
 &\
     "D,"
 &\
     m_strRecipientsFormat &\
     "D,"
 &\
     m_strAttachmentsFormat &\
   "}"

  
  m_lstMapiMessageData=[]
  m_lstMapiMessageData[1
]=0 
  m_lstMapiMessageData[2
]=m_ostrSubject.mevcGetStringPtr()
  m_lstMapiMessageData[3
]=m_ostrBody.mevcGetStringPtr()
  m_lstMapiMessageData[9
]=m_nRecipCount
  m_lstMapiMessageData[10
]=m_lstRecipientsArray
  m_lstMapiMessageData[11
]=m_nAttachCount
  m_lstMapiMessageData[12
]=m_lstAttachmentsArray
  
end


------------------------------------------------------------------------
------------------------------------------------------------------------
-- FUNCTION SendEmail
--
-- PURPOSE
--
-- calls the following EAPI as defined in mapi.h
--
-- ULONG FAR PASCAL MAPISendMail(
--     LHANDLE lhSession,         
--     ULONG ulUIParam,           
--     lpMapiMessage lpMessage,   
--     FLAGS flFlags,             
--     ULONG ulReserved           
--     );
--
------------------------------------------------------------------------
------------------------------------------------------------------------
on SendIt me
  
  --create the message structure
  BuildMAPIMessageStruct()
  
  --set the EAPI parameter values 
  lstArgVals=[]
  lstArgVals[1
]=0                     --lhSession
  lstArgVals[2]=0                     --ulUIParam
  lstArgVals[3]=m_lstMapiMessageData  --lpMessage
  lstArgVals[4]=0                     --flFlags
  lstArgVals[5]=0                     --ulReserved
  
  strArgFormat = "D,D,"
 & m_strMapiMessageFormat & ",D,D"
  
  --make the call though to the EAPI
  nErr=mevCallDllFun(m_strDllName,\
                     m_strFnName, \
                     strArgFormat,\
                     lstArgVals,\
                     m_strRetValFormat,\
                     m_lstRetVal)
  
  --check for exceptions
  
  
end


------------------------------------------------------------------------
------------------------------------------------------------------------
--end of script






  3d visualisation     data visualisation     interactive cds     printing     software     web design     training     games  
© Copyright 2006. Minds Eye Visualisation Services Limited. All Rights Reserved.