Announcement

Collapse
No announcement yet.

MAPI mail question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MAPI mail question

    I have been using the MAPI send mail functions I got at http://www.powerbasic.com/support/fo...ML/001025.html (0ld forum reference)

    I have been able to rework that to do everything I wanted to do except one thing: override the "From" email address.

    It always comes up with my 'index zero' sending address, [email protected], even though the "from" I enter is another valid address on my system, [email protected]

    Does anyone know how I can override the 'from' name and address?

    I have tried both "[email protected]" and "SMTP:[email protected]" as the "from."

    I am using Outlook Express 6.00.2900.2180

    MCM

    Ok, you want the code being used. It's not up to my regular "demo" standards but it should be good enough (it works here)..


    Code:
    ' FILE: MapiSendEmail.INC
    ' 7/24/08 New Include file containing exactly one function
    '         and all required support
    ' FUNCTION DEFINITION
    ' iRet = MapiSendEmail (szfrom, szTo, szCC, szAttach, szSubject, szText, SzErrMsg, BYVAL cbERRMsg )
    
    ' Where:
    ' szFrom =  NTS string with the 'from' email address. Required
    ' szTo   =  NTS string containing one or more "to" addresses. When multiple should be semi-colon delimited.
    '           Required.
    ' szCCTo =  NTS string containing one or more "CC" addresses. When multiple should be semi-colon delimited.
    '           Optional; pass BYVAL NULL if none
    ' szAttach  NTS string containing one or more file names to be attached. When multiple should be semi-colon delimited.
    '           Optional; pass BYVAL NULL if none'
    ' szSubject NTS string containing text to be used for the message subject. Required. (Not MAPI required)
    ' szTExt    NTS string containing text to be used for the message body.    Required. (Not MAPI required)
    ' szErrMsg  address and size of buffer into which an error message will be placed.
    ' cbErrMes
    ' Returns: On Sucess returns 0 (%MAPI_SUCCESS) and szErrMsg = "NO ERROR"
    '          Else returns error code and szErrMsg = Error text. If text too long it's truncated.
    
    ' ------------------------------------
    '    REQUIRED SUPPORT MATERIALS
    ' ------------------------------------
    
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "win32api.inc"
    #ENDIF
    
    #IF NOT %DEF(%MAPI_INC)
       #INCLUDE "MAPI.INC"
    
    #ENDIF
    
    '====================================================================
    ' Send one email, to, from, ccs , attachments .
    '====================================================================
    '
    
    
    FUNCTION MapiSendEmail ALIAS "TSMapiSendEmail" _
                (szFrom AS ASCIIZ, szTO AS ASCIIZ, szCCTO AS ASCIIZ, szAttach AS ASCIIZ, _
                 szSubject AS ASCIIZ, szBody AS ASCIIZ, szErrMsg AS ASCIIZ, BYVAL cchErrMsg AS LONG) AS LONG
    
    
      ' Attempt to load the MAPI library
      ' 6/8/08 why am I loading this dynamically instead of DECLARING with ALIAS?
    
      LOCAL szLib AS ASCIIZ * %MAX_PATH, szProc AS ASCIIZ * 64, dwProc AS DWORD
      LOCAL hLib AS LONG, iRet AS LONG
      
      LOCAL nTo AS LONG, nCC AS LONG, nAttach AS LONG
      LOCAL iRecip AS LONG, iAttach AS LONG
      LOCAL Z AS LONG
      LOCAL w AS STRING
      LOCAL sTo() AS STRING, sCC() AS STRING, sAttach() AS STRING, sAttachUser() AS STRING
      
      LOCAL MapiSession AS DWORD
      
      LOCAL mRECIP() AS MAPIRECIP
      LOCAL mATTACH() AS MAPIFILEDESC
      LOCAL mMessage  AS MAPIMESSAGE
      LOCAL iSendMailFlags AS LONG
    
    
      ' not currently used (7/24/08)
      LOCAL szProfile AS ASCIIZ * 128, szPassword AS ASCIIZ * 128
      LOCAL lpProfile AS DWORD, lpPassword AS DWORD
      
      LOCAL iMapiFlags AS LONG, hWnd AS LONG, Reserved AS LONG
      LOCAL szTimeStamp AS ASCIIZ * 32 ' required(?)
      
     
      '-----------------------------------------------------
      ' BEGIN CODE
      ' -----------------------------------------------------
      
      szErrMsg    =  "SUCCESS"     ' default
      szLib       =  $LIB_MAPI     ' constant in MAPI.INC
      hLib        =  LoadLibrary("MAPI32.DLL")
      IF ISFALSE hLib THEN
          szErrMsg    = USING$("Could not load MAPI library '&'", szLib)
          FUNCTION    = %TRUE   ' error
          EXIT          FUNCTION
      END IF
      
      
      ' These I will enhance at some point;
      ' will VARPTR(szProfile or szPassWord) at that time
      lpprofile   = %NULL
      lpPassword  = %NULL
      
      ' -----------------------------------
      ' LOGON AND ESTABLISH A MAPI SESSION
      ' -----------------------------------
      
      iMapiFlags = %MAPI_NEW_SESSION
      ' force a new session
      ' %MAPI_LOGON_UI flag ==> forces user to enter user Id and PW via a dialog
      '  I may want to have that as an option, too.
      
      hWnd = GetDesktopWindow()
      
      
      szProc = $PROC_MapiLogon
      dwProc =  getProcAddress (hLib, szProc)
      IF ISFALSE dwProc THEN
          szErrMsg    = USING$("Could not find procedure '&' in '&'", szProc, szLib)
          FreeLibrary   hLib
          FUNCTION    = %TRUE   ' error
          EXIT          FUNCTION
      ELSE
          CALL DWORD dwProc _
                USING U_MapiLogon _
                ( hWnd, _
                  BYVAL lpProfile, _
                  BYVAL lpPassword,_
                  iMapiFlags, _
                  Reserved, _
                  MapiSession) _
               TO iRet
          IF iRet <> %MAPI_SUCCESS THEN
              FreeLibrary   hlib
              szErrMsg    = USING$("Could not establish MAPI session; logon failed with return code #", iRet)
    
              FUNCTION    = %TRUE   ' error
              EXIT          FUNCTION
          END IF
     END IF
     
      ' --------------------------------------------
      ' IF we get here, we established MapiSession
      ' -------------------------------------------
      
      ' WE now need to build the MAPIMESSAGE stucture describing the message
      ' We WILL have pointers to arrays of Recipients, CC (both type MAPIRECIP)
      ' and may or may not have an array of files to attach (TYPE MAPIFILEDESC)
      
      
      ' get counts of number of recipients so we can size the recipient
      ' array.
      
      
        W       = szTO     ' dynamic string to work with
        nTo     = PARSECOUNT(W, ";")
        REDIM sTo (nTo-1)
        
        PARSE W, sTo(),";"
        
        IF ISTRUE VARPTR (szCCTO) THEN
            W   =  szCCTo
            nCC = PARSECOUNT(W,";")
            REDIM sCC (nCC-1)
            PARSE W, sCC(), ";"
        ELSE
            nCC = 0
        END IF
        
        ' Create an array of mRecips for sender, toaddresses and copies to:
        REDIM mRecip (nTo + nCC)    ' the extra one will be the sender
        ' make Mrecip(0) = the sender (originator)
        
         iRecip = 0
         mRecip(iRecip).iRecipClass  = %MAPI_ORIG
         mRecip(iRecip).lpszAddress  = VARPTR(szFrom)
        ' ----------------------------------------------------
        ' now get the details and build the recipient arrays
        ' ----------------------------------------------------
        W = szTO
        FOR Z = 0 TO nTO-1
            INCR   iRecip
            mRecip(iRecip).iRecipClass  = %MAPI_TO
            mRecip(iRecip).lpszAddress  = STRPTR(sTO(Z))
        
        NEXT Z
        
        IF nCC THEN
            FOR Z = 0 TO nCC -1
               INCR iRecip
               mRecip(iRecip).iRecipClass  = %MAPI_CC
               mRecip(iRecip).lpszAddress  = STRPTR(sCC(Z))
            NEXT Z
        END IF
    
        ' Get count of and build the attachments (if any)
        IF VARPTR (szAttach) THEN
            W        = szAttach
            nAttach  = PARSECOUNT (w, ";")
            REDIM sAttach (nAttach -1)
            PARSE W, sAttach(), ";"
            ' build a 'user file name' for each attachment
            ' will usually be 'file part' of full path name
            REDIM sAttachUser (nAttach-1)
            FOR Z = 0 TO nAttach -1
                IF DIR$(sAttach(Z)) = "" THEN
                    MSGBOX USING$("Cant find file # '&'", Z, sAttach(Z))
                END IF
                sAttachUser(Z) = USING$ ("File###", Z)
            NEXT Z
                
            
            
            REDIM  mAttach (nAttach-1)
    
            FOR Z = 0 TO nAttach-1
                mAttach(Z).iPosition =  -1&    ' -1 means 'as attachment'
                mAttach(Z).lpszPathName = STRPTR(sAttach(Z))
                ' pathname is fully qualified name of file as seen
                ' by MAPI;
                ' lpszFilename is name of file as seen by recipient
                ' so... I want to show only the filepart here
                 'mAttach(Z).lpszFileName = STRPTR(sAttachUser(Z))
                ' send as' works perfectly, when used
                ' if not used it is sent as 'filepart' of lpszpathename
            NEXT
        ELSE
            nAttach = 0
        END IF
        
        ' Since we have the sender, recipients and attachments
        ' set up we can now build the message itself
    
        
        RESET mMessage
        
        mMessage.lpszSubject      = VARPTR (szSubject)
        mMessage.lpszNoteText       = VARPTR (szBody)
        mMessage.lpszMessageType    = %NULL
        CALL  MapiCurrentTimeStamp () TO szTimeStamp
        mMessage.lpszDateReceived   = VARPTR (szTimeStamp)
        mMessage.lpszConversationID = %NULL
        mMessage.iFlags             = %MAPI_NEW_SESSION
        mMessage.lpOriginator       = VARPTR (mRecip(0)) ' sender is at 0
        mMessage.iRecipCount        = nTO + nCC
        mMessage.lpRecips           = VARPTR (mRecip(1))  ' to and CC start at subscript 1
        mMessage.iFileCount         = nAttach
        mMessage.lpFiles            = IIF&(nAttach, VARPTR(mAttach(0)), %NULL)
    
        ' -------------------------------------------
        ' WE CAN NOW CALL MAPI TO SEND THE MESSAGE
        ' -------------------------------------------
        szProc   = $PROC_MAPISendMail
        dwProc   = GetProcAddress(hLib, szProc)
        
        iSendMailFlags = %MAPI_NEW_SESSION
        ' valid flags here: none, MAPI_DIALOG, %MAPI_NEW_SESSION, %MAPI_LOGON_UI
    
        CALL DWORD dwProc _
           USING U_MapiSendMail _
             (MapiSession, _
               HWnd, _
               mMessage, _
               iSendMailFlags, _
               Reserved) _
            TO iRet
            
        IF iRet <> %MAPI_SUCCESS THEN
            szErrMsg = USING$ ("MapiSendMail Failed with code #", iRet)
        END IF
            
               
        szProc  = $PROC_MapiLogoff
        dwPRoc  = GetProcAddress(hLib, szPRoc)
        CALL DWORD dwProc USING U_MapiLogoff(MapiSession, 0, 0, 0)
        ' no I do not want the return value here
        
      ' Free the Library and exit
        FreeLibrary hLib
        FUNCTION = iRet
    
    END FUNCTION
    
    '--------------------------------------------------------------------
    
    ' Required "The format is YYYY/MM/DD HH:MM, using a 24-hour clock."
    FUNCTION MapiCurrentTimeStamp () PRIVATE AS STRING
        LOCAL st AS SYSTEMTIME
        LOCAL szDF AS ASCIIZ * 48,  szDate AS ASCIIZ * 48
        LOCAL szTF AS ASCIIZ * 48,  szTime AS ASCIIZ * 48
    
    
        GetLocalTime     st
        szDf          =  "yyyy'/'MM'/'dd"
        GetDateFormat    BYVAL %NULL, BYVAL %NULL ,st, szDf, szDate, SIZEOF (szDate)
    
        szTF          = "HH':'mm"
        GettimeFormat    BYVAL %NULL, BYVAL %NULL ,st, szTF, szTime, SIZEOF (szTime)
    
        FUNCTION = szDate & $SPC & szTime
    END FUNCTION
    
    
    
    ' ** END OF FILE ***
    I suppose you'll want this, too...
    Code:
    ' FILE: MAPI.INC
    ' Created by MCM to use in INCLUDE folder (when working).
    ' A PB conversion of Windows "mapi.h" file is not provided by PowerBASIC inc with the compilers.
    ' I wonder if someone has done this and I can just go get it? I got don d's and may use
    ' NOTE: This version does not use MAPI32.DLL
    ' compiled OK 7/24/08
    
    
    ' -----------------
    ' #INCLUDE CONTROL
    ' ------------------
    
    #IF NOT %DEF (%WINAPI)
       #INCLUDE "WIN32API.INC"
    #ENDIF
    #IF NOT %DEF (%MAPI_INC)
        %MAPI_INC = 1
        
    
    ' -------------------------------------------------------------
    ' MAPI constants; source: MAPI.H (not provided by PB compiler)
    ' -------------------------------------------------------------
    
    %MAPI_LOGON_UI    = 1
    %MAPI_NEW_SESSION = 2
    %MAPI_DIALOG      = 8
    
    
    ' Recipient Class values:
    %MAPI_ORIG        = 0
    %MAPI_TO          = 1
    %MAPI_CC          = 2     '  /* Recipient is a copy recipient            */
    %MAPI_BCC         = 3     '  /* Recipient is blind copy recipient        */
    
    
    ' MAPI structures
    TYPE MAPIRECIP
      iReserved     AS LONG
      iRecipClass   AS LONG
      lpszName      AS ASCIIZ PTR
      lpszAddress   AS ASCIIZ PTR
      iEIDSize      AS LONG
      lpEntryID     AS DWORD
    END TYPE
    
    TYPE MAPIFILEDESC
      iReserved     AS LONG
      iFlags        AS LONG
      iPosition     AS LONG
      lpszPathName  AS ASCIIZ PTR
      lpszFileName  AS ASCIIZ PTR
      lpFileType    AS DWORD
    END TYPE
    
    TYPE MAPIMESSAGE
      iReserved          AS LONG
      lpszSubject        AS ASCIIZ PTR
      lpszNoteText       AS ASCIIZ PTR
      lpszMessageType    AS ASCIIZ PTR
      lpszDateReceived   AS ASCIIZ PTR
      lpszConversationID AS ASCIIZ PTR
      iFlags             AS LONG
      lpOriginator       AS MAPIRECIP PTR
      iRecipCount        AS LONG
      lpRecips           AS MAPIRECIP PTR
      iFileCount         AS LONG
      lpFiles            AS MAPIFILEDESC PTR
    END TYPE
    
    ' ----------------------------------------------
    ' MAPI function templates for CALL DWORD USING
    ' ----------------------------------------------
    ' MCM note to self: why these functions do not use the "LIB ALIAS" format is
    ' a mystery to me. However, I will go along with this
    
    ' --------------------------------------------------
    '  LIBRARY AND PROCEDURE NAMES FOR CALL-BY_ADDRESS
    ' ---------------------------------------------------
    $LIB_MAPI= "MAPI32.DLL"
    
    $PROC_MapiLogon   = "MAPILogon"
    $PROC_MapiLogoff  = "MAPILogoff"
    $PROC_MapiSendMail = "MAPISendMail"
    
    DECLARE FUNCTION U_MapiLogon(BYVAL iParam AS LONG, _
                               zName AS ASCIIZ, _
                               zPW AS ASCIIZ, _
                               BYVAL iFlags AS LONG, _
                               BYVAL iReserved AS LONG, iSession AS LONG) AS LONG
    
    DECLARE FUNCTION U_MapiLogoff(BYVAL iSession AS LONG, _
                                BYVAL iParam AS LONG, _
                                BYVAL iFlags AS LONG, _
                                BYVAL iReserved AS LONG) AS LONG
    
    DECLARE FUNCTION U_MapiSendMail(BYVAL iSession AS LONG, _
                                 BYVAL iParam AS DWORD, _
                                 lpMapiMessage AS MAPIMESSAGE, _
                                 BYVAL iFlags AS LONG, _
                                 BYVAL iReserved AS LONG) AS LONG
    
    
    
    
    ' -------------------------------------
    '  MAPI ERROR CODES FROM mapi.h
    ' ------------------------------------
    %SUCCESS_SUCCESS                = 0
    %MAPI_SUCCESS                   = %SUCCESS_SUCCESS ' MCM equate only
    %MAPI_USER_ABORT                = 1
    %MAPI_E_USER_ABORT              = %MAPI_USER_ABORT
    %MAPI_E_FAILURE                 = 2
    %MAPI_E_LOGON_FAILURE           = 3
    %MAPI_E_LOGIN_FAILURE           = %MAPI_E_LOGON_FAILURE
    %MAPI_E_DISK_FULL               = 4
    %MAPI_E_INSUFFICIENT_MEMORY     = 5
    %MAPI_E_ACCESS_DENIED           = 6
    %MAPI_E_TOO_MANY_SESSIONS       = 8
    %MAPI_E_TOO_MANY_FILES          = 9
    %MAPI_E_TOO_MANY_RECIPIENTS     = 10
    %MAPI_E_ATTACHMENT_NOT_FOUND    = 11
    %MAPI_E_ATTACHMENT_OPEN_FAILURE = 12
    %MAPI_E_ATTACHMENT_WRITE_FAILURE= 13
    %MAPI_E_UNKNOWN_RECIPIENT       = 14
    %MAPI_E_BAD_RECIPTYPE           = 15
    %MAPI_E_NO_MESSAGES             = 16
    %MAPI_E_INVALID_MESSAGE         = 17
    %MAPI_E_TEXT_TOO_LARGE          = 18
    %MAPI_E_INVALID_SESSION         = 19
    %MAPI_E_TYPE_NOT_SUPPORTED      = 20
    %MAPI_E_AMBIGUOUS_RECIPIENT     = 21
    %MAPI_E_AMBIG_RECIP             = %MAPI_E_AMBIGUOUS_RECIPIENT
    %MAPI_E_MESSAGE_IN_USE          = 22
    %MAPI_E_NETWORK_FAILURE         = 23
    %MAPI_E_INVALID_EDITFIELDS      = 24
    %MAPI_E_INVALID_RECIPS          = 25
    %MAPI_E_NOT_SUPPORTED           = 26
    
    
    
    #ENDIF   ' if not %DEF (%MAPI_INC)
    Well, I'm in this deep I may as well give you the demo program code, too..
    Code:
    ' TEST_INCLUDE FILES
    ' INCLUDE FILE WORKING PERFECTLY AS OF
    ' 7-24-08.
    ' Except: if invalid path name specified in attachment,
    ' send fails with error two.
    ' ergo, the send function must filter out (or error out)
    ' if it cannot find one or more of the files.
    ' Onlyissues:
    ' I still cannot seem to send with 'from' anything
    ' other than my default address of [email protected]
    
    
    #COMPILE  EXE
    #DEBUG    ERROR ON
    #REGISTER NONE
    #DIM      ALL
    #TOOLS    OFF
    '=====[Windows API Header Files] ============================
    '  If you don't need all of the functionality supported by these APIs
    '  (and who does?), you can selectively turn off various modules by putting
    '  the following constants in your program BEFORE you #include "win32api.inc":
    '
    '  %NOGDI = 1     ' no GDI (Graphics Device Interface) functions
    '  %NOMMIDS = 1   ' no Multimedia ID definitions
    
    %NOMMIDS = 1
    #INCLUDE "WIN32API.INC"
    '==[End Windows API Header Files]============================
    
    #IF NOT %DEF (%INVALID_HANDLE_VALUE_LONG)
       %INVALID_HANDLE_VALUE_LONG    = -1&
    #ENDIF
    
    
    ' ---------------------
    ' Include Mapi functions
    ' in new #INCLUDE file
    
    #INCLUDE "MapiSendEmail.INC"
    
    
    
    FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _
                      BYVAL hPrevInstance AS LONG, _
                      BYVAL lpCmdLine     AS ASCIIZ PTR, _
                      BYVAL iCmdShow      AS LONG) AS LONG
                      
       
     CALL TestSendMail
       
       
    END FUNCTION
    
    ' ---------------------------
    ' Test new function 7/24/08
    ' ---------------------------
    
    
    
    FUNCTION TestSendMail () AS LONG
        
      LOCAL szFrom AS ASCIIZ * 128
      LOCAL sTo AS STRING, sCC AS STRING
      LOCAL sAttach AS STRING
      LOCAL lpTo  AS LONG, lpCC AS LONG, lpAttach AS LONG
      
      LOCAL szSubject AS ASCIIZ * %MAX_PATH, szBody AS ASCIIZ * %MAX_PATH
      
      LOCAL szErrMsg AS ASCIIZ * %MAX_PATH
      LOCAL cbErrMsg AS LONG
      LOCAL iRet AS LONG
      
      cbErrMsg = SIZEOF(szErrMsg) -1
      
      ' This is good testing for me; the mail will go into my outbox
      ' because that is the way my Outlook Express is set up
      ' I can change that to test 'actual' sending when
      ' this is ready for final testing.
      
      
      
      
      szSubject = "This is the subject"
      szBody    = "This is the body"
      szFrom    = "[email protected]"   ' not my default address
      ' **** [email protected] is not a valid address on my system!***
      ' but [email protected] is and that still does not work!
      
      ' it still sends as from [email protected]
      
      ' -------------------------------------------------
      ' both "to" and "CC" may be semi-colon delimited
      ' addresses. test first with one of each
      ' -------------------------------------------------
      
      sTo  = "[email protected];[email protected]"
      sCC  = "[email protected];[email protected]"
      
      
      sAttach = "D:\Software_development\Projects\Email June 2008\mapi.inc"
      
      sAttach = sAttach & ";" & "D:\Software_development\Projects\Email June 2008\mapi.bak"
      
      sAttach = sAttach & ";" & "D:\Software_development\Projects\Email June 2008\Test_Include_files.exe"
      
      lpTO      = IIF( LEN(sTo) > 0 ,STRPTR(sTo), %NULL)
      lpCC      = IIF(LEN(sCC), STRPTR(sCC), %NULL)
      lpAttach  = IIF(LEN(sAttach), STRPTR(sAttach), %NULL)
      
      ' I have an error in the attachments resuluting
      ' in error 2 (MAPI_E_FAILURE)
      
      
      
      
      iRet = MapiSendEmail _
                   (szFrom,_
                    BYVAL lpTo, _
                    BYVAL lpCC, _
                    BYVAL lpAttach, _
                    szSubject, _
                    szBody, _
                    szErrMsg, _
                    cbErrMsg)
                    
                    
          MSGBOX USING$ ("iRet #  &", iRet, szErrMsg),,"Test MAPI Mail"
          
          
      
    END FUNCTION
     
    ' END OF FILE
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

  • #2
    Hi Michael,

    I've tinkered with this and think perhaps it is a limitation of the Outlook Express Simple MAPI implementation. As far as I can tell it always picks up the senders name and email address from the default email account details in OE6.

    I am using Outlook Express 6.00.2900.5512

    The only way I have been able to send an email from your code with a different 'from' address is to change the default Outlook Express mail account within OE6.

    Outlook Express 6...
    Tools menu...
    Accounts menu...
    Mail tab...
    Select alternative account...
    Click [Set as Default] button

    I tried a couple of other things.

    1) In order to manually select another account (profile?), I tried getting the logon dialog box to appear by passing %MAPI_LOGON_UI to the MapiLogon call without success.

    According to http://msdn.microsoft.com/en-us/libr...EXCHG.10).aspx

    "A logon dialog box should be displayed to prompt the user
    for logon information. If the user needs to provide a password
    and profile name to enable a successful logon, MAPI_LOGON_UI
    must be set."

    Maybe I did something wrong, but I never saw a dialog box.


    2) I tried using an alternative account/password as the ProfileName/Password in the MapiLogon call which didn't work. Which it turns out is due to a Microsoft design choice.

    http://support.microsoft.com/kb/315503

    SYMPTOMS
    When Outlook Express is the default mail client, the MAPILogon function ignores the profile name and password parameters.

    CAUSE
    Because Outlook Express does not use profiles, MAPILogon uses the default identity.

    STATUS
    This behavior is by design.

    I am by no means expert in this area so you may find someone else will come up with a solution. Good luck.

    All the Best,

    David

    Comment


    • #3
      Thank you for the info; very informative.

      Maybe someone with a mail client other than Outlook Express will try this and watch it work 'as I wanted it to' ... which would be just fine with me.

      I can live with just about anything as long as I know what to expect.

      Microsoft Outlook (non-Express) results would be of great interest to me.

      > am by no means expert in this area

      Join the crowd.

      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        I did a little more research and found a related item.

        http://www.vbforums.com/showthread.php?t=503328

        Question: "How do I specify a different "From" address so that it does not use my default OE6 email address but my other email address instead?"

        Reply: You could monitor the registry and see how OE specifies the default account in the registry. Then change account defaults via code.


        It sounds a bit hacky perhaps (but interesting) so I went and found where OE6 stores its default account settings in the registry.

        http://www.insideoe.com/files/regkeys.htm#regIAMkey

        The Internet Account Manager registry key
        |-HKEY_CURRENT_USER
        |----Software
        |-------Microsoft
        |----------Internet Account Manager

        The 'Default Mail Account' key is set to the point at one of the account sub-keys.

        |-------------Accounts
        |----------------00000001
        |----------------00000002
        etc.

        > I can live with just about anything as long as I know what to expect.

        It might be sufficiently predictable then for your code to furtle around in the registry and...

        1) Look up and store the original 'Default Mail Account' value.
        2) Enumerate the available OE accounts retrieving their sub-key values.
        3) Set the "Default Mail Account" key to the sub-key of the one with a matching 'Account Name' to be specified in your code.
        4) Send the email from your code which would use the 'new' default.
        5) Set the "Default Mail Account" key back to its original value.


        David

        Comment


        • #5
          Since this is being dropped in to customer application and he is having trouble installing the (required) MAPI client on the computer he will be using for this application, I have a better idea:

          "If you choose Outlook Express as your MAPI mail client for this application, the "From" will always be the default OE email account, as OE does not respect the commands to use another."

          (Hard to believe I was once a genuine hacker, huh?)

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            With this being required for a customer application, I think avoiding this 'solution' would be sensible.

            It might create a situation where (as a colleague of mine used to say), 'things could get worse without limit'.

            David

            Comment


            • #7
              I changed my OE default sender (using the provided interface, not by hand-editing the registry) and sure enough, the new default email was used as the "from."

              This particular customer application will be using an essentially dedicated machine, and for sure this will be the only email application on that box, so OE is very usable.

              MCM


              PS: I'd still be interested in anyone who DOES get "from address on demand" and which email client(s) actually listen when told.
              Last edited by Michael Mattias; 26 Jul 2008, 11:11 AM.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Using CDOSYS.DLL
                http://www.powerbasic.com/support/pb...ghlight=cdosys

                http://www.aspfree.com/c/a/Windows-S...ing-CDOSYSDLL/
                Last edited by Mike Doty; 26 Jul 2008, 06:52 PM.

                Comment


                • #9
                  I don't know the purpose of that application, but in general sending out emails (to outside recepients) with all emial addresses in the CC field, is considered back practice. You put the recipients in the BCC field instead.

                  Depending on where that appilcation is used, this might even violate privacy laws (your not supposed to share any personal data, which an email address is, with a 3rd party).

                  If that's an inhouse application, all's fine, though ...

                  Comment


                  • #10
                    Strangely enough, Knuth, they WANT the "CCs" shown.

                    This is the "create PDF-files" invoice application I've mentioned here before.

                    In some cases my client's customers want invoices sent to the 'home office' with a CC to the 'branch office' and in other cases they want the inverse.

                    In either case, my client wants his customers to know who got copies.

                    MCM
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Ah, I see. That sounds like a reasonable usage of the CC field.

                      Comment


                      • #12
                        Hi Mike,

                        While I haven't had a change to play with this using Thunderbird, outlook, or pegasus (the packages I've got installed). . .

                        Just for grins - did you try creating another user account on the machine and the "Run As" your program?

                        To the best of my knowledge, the "default email" is on a per user basis.

                        Worth a try.

                        Going back to homework now...
                        JS
                        John,
                        --------------------------------
                        John Strasser
                        Phone: 480 - 273 - 8798

                        Comment


                        • #13
                          Michael
                          Why not just write your own, much simpler and much more reliable, then you don't have to worry about which mail client is installed and all their different abilities. I got caught once in VB6, using COM to Outlook for a special customer, worked fine. He decided it would be nice to have it for another user who only had Express so of course it wouldn't work there.
                          My accountant uses a major accounting package that sends reports by email, he uses Outlook, the program dumps the sent notifications into Express that is still installed but not used Duh.
                          Some good examples in both the forums and download sections. I just have a small DLL which replaces the MAPI send functions so just add it into my programs with either an INI or Textboxes (or both) for each customers requirements.
                          John

                          Comment


                          • #14
                            >Why not just write your own,

                            My own what?

                            I was creating an application designed specifically to "use your installed MAPI email client to send email as a batch program you can execute on demand."

                            Matter of fact, I will probably be releasing the finished version of the above as "freeware" (well, there will be at least a little shameless self-promotion involved, a splash screen maybe) quite soon. I'm even paying someone to write a help file for it. (See, posting in the "Positions Offered" forum has made someone here a few shekels).

                            However.... I am thinking about also creating a "use SMTP to send email as a batch program you can execute on demand" application. I think this would make a nice "matched set." Don't you?

                            (I do applications, not all that geeky system stuff).


                            MCM
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              SMTP:
                              http://www.greatwebdivide.com/software_ddsmtp.htm

                              Comment


                              • #16
                                Originally posted by Michael Mattias View Post
                                >Why not just write your own,

                                My own what?

                                I was creating an application designed specifically to "use your installed MAPI email client to send email as a batch program you can execute on demand."

                                Matter of fact, I will probably be releasing the finished version of the above as "freeware" (well, there will be at least a little shameless self-promotion involved, a splash screen maybe) quite soon. I'm even paying someone to write a help file for it. (See, posting in the "Positions Offered" forum has made someone here a few shekels).

                                However.... I am thinking about also creating a "use SMTP to send email as a batch program you can execute on demand" application. I think this would make a nice "matched set." Don't you?

                                (I do applications, not all that geeky system stuff).


                                MCM
                                Nothing Geeky look at the tcp/ip samples in your whatever version install. Look forward to your batch files to do what so many code examples on these forums on a one off or as needed send an email. Guess you only look at your own posts for usable examples. If I had time I would offer to take the sheklels but no splash screen in PB the emails would be gone before the splash screen can display.

                                Comment


                                • #17
                                  >Guess you only look at your own posts for usable examples

                                  You gotta be kidding. I take plenty, which is why I try to give at least plenty.

                                  One From Column A, One from Column B..
                                  Michael Mattias
                                  Tal Systems (retired)
                                  Port Washington WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment


                                  • #18
                                    My comment about the geeky system stuff is based on the fact that many of the code samples are in fact demos of a single function. (Including several of my own) .

                                    But an application requires more than one function, especially when it's Susie User who will be driving.

                                    MCM
                                    Michael Mattias
                                    Tal Systems (retired)
                                    Port Washington WI USA
                                    [email protected]
                                    http://www.talsystems.com

                                    Comment


                                    • #19
                                      Michael
                                      I think there is a little terminolgy confusion here. You don't need to bother about SMTP, you just need to write a pop3 client which is what MAPI normally uses, though it has other features. The samples in the downloads are complete including MIME encoding of attachments etc. Shouldn't take much extra time over the user interface you will need to write for MAPI anyway.
                                      John

                                      Comment


                                      • #20
                                        I don't want a POP3 client. I don't want SMTP. I don't even want MAPI.

                                        I want an application to to "send email as a batch program you can execute on demand."

                                        I chose to do this version using the MAPI interface. Only thereafter did I learn that there are some limitations in one of your more popular MAPI Clients: Outlook Express.

                                        That's why I am thinking about doing a version to use SMTP, to both remove those restrictions and not require an installed MAPI client.

                                        BTW - he said in a shameless display of promoting someone else's work - I got my "first draft" of the help file for the current software from Frank Kelly of OnTop Systems, who has advertised here in the third-party forum.

                                        I was so impressed I simply could not send an email, I had to phone to let him know how pleased I was with his work. I never dreamt a 'first draft' could be this close to 'finished.'

                                        MCM
                                        Michael Mattias
                                        Tal Systems (retired)
                                        Port Washington WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

                                        Working...
                                        X