May 18, 2012, 09:44:54 pm
News: Welcome to NPL Community Forum.
Please let us know what you think, and let's get the other developers on here, so we can work together to move NPL to the next level.
Pages: [1]   Go Down
Print
Author Topic: Sending eMail...  (Read 1688 times)
0 Members and 1 Guest are viewing this topic.
basic2c
Developers
****
Offline Offline

Posts: 35


bspeng
View Profile WWW Email
« on: February 26, 2008, 11:00:00 am »

What is a best way to send email via NPL?

What about retrieving email?

Logged
SeaFree
Developers
****
Offline Offline

Posts: 3


View Profile Email
« Reply #1 on: April 24, 2008, 12:33:07 am »

Re: Sending eMail

Some years back, I had an idea about using NPL to send email.  I never actually used this module in a production product so it may needs some tweaks.  For example, you may need some $DECLARE statements that don't exist in this module.   I hope this helps.

SeaFree

!!!!!!!!!!!!!!!!!!!!!!  UN4MAIL !!!!!!!!!!!!!!!!!!!!!!!!!

0010 % UN4MAIL = 09/05/03 = 11/30/00 = eMail Utility Based On Simple MAPI calls 

     
0020 DIM _UINT4$=HEX(D004)
     DIM _LPSTR$=HEX(D004)  : ; must be set to 0 or pointer to C string.
     
     DIM _SUCCESS_SUCCESS=0
     DIM _MAPI_LOGON_UI=1: ; Display logon UI if required
     DIM _Null$0
     DIM _MAPI_ORIG=0: ;Indicates the original sender of the message.
     DIM _MAPI_TO=1  : ;Indicates a primary message recipient
     DIM _MAPI_NEW_SESSION=2   : ; Force new session
     
     
     
0030 RECORD MapiMessage
       FIELD mm_Reserved=_UINT4$
       FIELD mm_Subject=_LPSTR$
       FIELD mm_NoteText=_LPSTR$
       FIELD mm_MessageType=_LPSTR$
       FIELD mm_DateReceived=_LPSTR$
       FIELD mm_ConversationID=_LPSTR$
       FIELD mm_Flags=_UINT4$
       FIELD mm_Originator=_LPSTR$
       FIELD mm_RecipCount=_UINT4$
       FIELD mm_Recips=_LPSTR$
       FIELD mm_FileCount=_UINT4$
       FIELD mm_Files=_LPSTR$
     END RECORD MapiMessage
     
     
     RECORD MapiRecipDesc
       FIELD mr_Reserved=_UINT4$
       FIELD mr_RecipClass=_UINT4$
       FIELD mr_Name=_LPSTR$
       FIELD mr_Address=_LPSTR$
       FIELD mr_EIDSize=_UINT4$
       FIELD mr_EntryID=_LPSTR$
     END RECORD MapiRecipDesc
     
     
     RECORD MapiFileDesc
       FIELD mf_Reserved=_UINT4$
       FIELD mf_Flags=_UINT4$
       FIELD mf_Position=_UINT4$
       FIELD mf_PathName=_LPSTR$
       FIELD mf_FileName=_LPSTR$
       FIELD mf_FileType=_LPSTR$
     END RECORD MapiFileDesc
     
     
0040 $DECLARE 'CastLPSTR(/POINTER DIM() _X$) TO INT(4)="MSVCRT.abs"
     
     
     $DECLARE 'MAPILogon(INT(4) _UIParam,
                        STR() _ProfileName$,
                        STR() _Password$,
                        INT(4) _Flags,
                        INT(4) _Reserved,
                                       TO RETURN INT(4) Session) TO INT(4)="MAPI32.MAPILogon"
     
     $DECLARE 'MAPISendMail(INT(4) Session,
                            INT(4) UIParam,
                                TO RETURN DIM(#RECORDLENGTH(MapiMessage)) MapiMessage$,
                                TO RETURN INT(4) Flags,
                            INT(4) Reserved)="MAPI32.MAPISendMail"
     
       
     $DECLARE 'MAPILogoff(INT(4) Session,
                         INT(4) UIParam,
                         INT(4) Flags,
                         INT(4) Reserved) TO INT(4)="MAPI32.MAPILogoff"
     
     
     
0100 FUNCTION 'DisableNPLReorg(_flag)
       DIM option_was$1,
           option_was,
           O$64
     
       O$=$OPTIONS
       option_was$=STR(O$,47,1) AND HEX(10)
       option_was=VAL(option_was$)
       ;
       IF _flag
          STR(O$,47,1)=OR HEX(10)
       ELSE
          STR(O$,47,1)=BOOL4 HEX(10)
       END IF
       ;
       $OPTIONS=O$
       RETURN (option_was)
     END FUNCTION
     
     
     
0200 PROCEDURE 'AppendNull(/POINTER Text$)
       IF STR(Text$,LEN(Text$),1)<>HEX(00)
         Text$=Text$ & HEX(00)
       END IF
     END PROCEDURE
     
     
     
1000 FUNCTION 'SendMail(/POINTER SenderName$,
                        /POINTER SenderAddress$,
                        /POINTER RecipName$,
                        /POINTER RecipAddress$,
                        /POINTER Subject$,
                        /POINTER Text$,
                        Number_of_Attachments,
                        /POINTER Attachment_Filenames$(),
                        flgs)/PUBLIC
                       
     DIM MapiSession=0,
         MapiMessage$#RECORDLENGTH(MapiMessage),
         MapiRecipDesc$#RECORDLENGTH(MapiRecipDesc),
         MapiOrigDesc$#RECORDLENGTH(MapiRecipDesc),
         ReorgWas,
         Mapi_Session,
         Mapi_Error,
         Flags,
         I,
         Work$256
     
     DIM /STATIC MapiFilesList$(0)#RECORDLENGTH(MapiFileDesc)
     
     Flags=flgs
     
     ; Append Null Terminator Characters
     'AppendNull(SenderName$)
     'AppendNull(SenderAddress$)
     'AppendNull(RecipName$)
     'AppendNull(RecipAddress$)
     'AppendNull(Subject$)
     'AppendNull(Text$)
     
     IF Number_of_Attachments>0
       FOR I=1 TO Number_of_Attachments BEGIN
         'AppendNull(Attachment_Filenames$(I))
       NEXT I
     END IF
     ;
     ReorgWas='DisableNPLReorg(1)
     ;
     ;login to default environment, default session
     Mapi_Error='MAPILogon(0,  ;no parent window
                        _Null$, ;profile name (get from dialog?)
                        _Null$, ;password
                        Flags,  ;Flags
                        0,  ;Reserved,
                        Mapi_Session)
     
     IF Mapi_Error=_SUCCESS_SUCCESS
        ;define the sender
        MapiOrigDesc$=ALL(00)
        MapiOrigDesc$.mr_RecipClass=_MAPI_ORIG
        MapiOrigDesc$.mr_Name='CastLPSTR(SenderName$)
        MapiOrigDesc$.mr_Address='CastLPSTR(SenderAddress$)
        ;mr_EIDSize=0
        ;mr_EntryID=0
        ;           
        ;define the recipient
        MapiRecipDesc$=ALL(00)
        MapiRecipDesc$.mr_RecipClass=_MAPI_TO
        MapiRecipDesc$.mr_Name='CastLPSTR(RecipName$)
        MapiRecipDesc$.mr_Address='CastLPSTR(RecipAddress$)
        ;
        ;mr_EIDSize=0
        ;mr_EntryID=0
        ;
        ;define the subject and text for the message
        MapiMessage$=ALL(00)    : ;init to all 0/ NULL
        MapiMessage$.mm_Subject='CastLPSTR(Subject$)
        MapiMessage$.mm_NoteText='CastLPSTR(Text$)
        MapiMessage$.mm_Originator='CastLPSTR(MapiOrigDesc$)
        MapiMessage$.mm_RecipCount=1
        MapiMessage$.mm_Recips='CastLPSTR(MapiRecipDesc$)
       
       
1100    ;make a list of attachment files structures
        REDIM MapiFilesList$(Number_of_Attachments)#RECORDLENGTH(MapiFileDesc)
       
        IF Number_of_Attachments>0
          ;
          FOR I=1 TO Number_of_Attachments
            MapiFilesList$(I)=ALL(00)
            MapiFilesList$(I).mf_Flags=0    : ;data file
            MapiFilesList$(I).mf_Position=VAL(HEX(FFFFFFFF),4)
           
            MapiFilesList$(I).mf_PathName='CastLPSTR(Attachment_Filenames$(I))
            MapiFilesList$(I).mf_FileName=0: ;name recipient sees
            MapiFilesList$(I).mf_FileType=0: ;unknown file type         
          NEXT I
          ;
          MapiMessage$.mm_FileCount=Number_of_Attachments
          MapiMessage$.mm_Files='CastLPSTR(STR(MapiFilesList$()))
        END IF
        ;
        ;send it!
        ;
        Mapi_Error='MAPISendMail(Mapi_Session,
                                 0,
                                 MapiMessage$,
                                 Flags,
                                 0)
        IF Mapi_Error
            msg$="MapiSendMail Error #" & 'FMTL$("######",Mapi_Error)
            'MsgBox(msg$,"Problem Sending Mail",_vbExclamation)
            ;refer to C mapi.h file for error meaning
        ELSE
            ;sent successfully
        END IF
        Mapi_Error='MAPILogoff(Mapi_Session,0,0,0)
       ;
     END IF
     ;
     ReorgWas='DisableNPLReorg(ReorgWas)
     Work$=$RUNDIR
     'SetCurrentDirectoryA(Work$)
     RETURN (Mapi_Error)
     ;
     END FUNCTION
     
     
5000 DIM Attachment_Filenames$(10)255
     
     DIM SenderName$100,
         SenderAddress$100,
         RecipName$100,
         RecipAddress$100,
         Subject$100,
         Text$1000
     ;
     Attachment_Count=1
     Attachment_Filenames$(1)=NPL_RunDir$ & "APM.INI"
     ;
     SenderName$=SSC_ShortUserName$
     SenderAddress$=" "
     ;
     RecipName$="Your email name"
     RecipAddress$="YourEmailAddress@DomainName.com"
     ;
     Subject$="Sending file "
     Text$="User: " & SSC_ShortUserName$ & HEX(0D0A) & "File: " & Attachment_Filenames$(1)
     
5010 send_error='SendMail(SenderName$,
                          SenderAddress$,
                          RecipName$,
                          RecipAddress$,
                          Subject$,
                          Text$,
                          Attachment_Count,
                          Attachment_Filenames$(),
                          _MAPI_LOGON_UI)
     
5020 IF send_error<>0
       msg$="Error " & 'FMTL$("###########",send_error) & " occurred while attempting to eMail the file"
       'MsgBox(msg$," ",_vbExclamation)
     END IF
     ;
     LOAD T "EXITPROG"
 
« Last Edit: April 24, 2008, 02:43:44 pm by Mr. Niakwa » Logged
Pages: [1]   Go Up
Print
Jump to: