************ * DO * * SendMail * * routine * * here. * ************ WAIT WINDOW NOWAIT NOCLEAR "Please Wait... Sending Electronic Change Order Files" * Send mail using MSMAPI * Based on HOWTO: Send a Message in Visual FoxPro Using Active Messaging (Q175052) * Create a MAPI Session object then Logon. The Logon dialog can be * bypassed by providing a valid ProfileName as the first parameter * (as a string) to the Logon Method as seen below. objSession = CREATEOBJECT("mapi.session") * objSession.Logon("YourProfileName") objSession.Logon SELECT Members && Members.dbf = ChgOrder Mail Recipients * There should always be a record for Glenda Burger * in Members.dbf with Flag="P" [(P)rice Quotes] LOCATE FOR Flag = "P" IF EOF() = .T. INSERT INTO Members ; (Name, ; Address, ; Flag) ; VALUES ; ("GLENDA BURGER", ; "Glenda Burger", ; "P") ENDIF * Keep track of how many times you loop thru. * Should loop thru 1 time for mWhoGets = "P" and * should loop thru an additional time for mWhoGets * = "C" "E" or "W" (TOTAL of 2 times thru, but not 3) STORE 1 TO mSendCounter STORE "P" TO mWhoGets && Glenda always receives; so, start with her! DO WHILE mSendCounter <> 3 LOCATE FOR Flag = mWhoGets IF EOF() = .T. MESSAGEBOX("You have no recipients set up to receive" + CHR(13) + ; "order changes flagged as '" + mWhoGets + ".'" + CHR(13) + ; CHR(13) + ; "Go into the Change Order Recipients screen" + CHR(13) + ; "and add recipients as necessary." + CHR(13) + ; CHR(13) + ; "This Change Order transmission will now be cancelled.", ; 0+16+0, ; "Error: No Recipients found for '" + mWhoGets + ".'") RETURN ENDIF SET FILTER TO Members.Flag = mWhoGets SCAN * Create a new message in the Outbox and populate a few basic properties. objMessage = objSession.Outbox.Messages.Add objMessage.Subject = "Change Order " + Ord_Ma(2) objMessage.Text = "Change for Order Number: " + Ord_Ma(2) * Attach the proper attachment IF mWhoGets = "P" objMessage.Attachments.Add("ChOPrice.txt", 0, 1, "C:\ChgOrder\ChOPrice.txt") ELSE objMessage.Attachments.Add("ChgOrder.txt", 0, 1, "C:\ChgOrder\ChgOrder.txt") ENDIF * Add a Recipient to the message we just created and resolve objRecip = objMessage.Recipients.Add(ALLTRIM(Name)) objRecip.Resolve * Send it objMessage.Send ENDSCAN IF Ord_Ma(8) <> "No Change" && No Warehouse Changes STORE "W" TO mWhoGets ENDIF IF Ord_Ma(7) = "EASTLAND" STORE "E" TO mWhoGets ENDIF IF Ord_Ma(7) = "CORDELE" STORE "C" TO mWhoGets ENDIF mSendCounter = mSendCounter + 1 SET FILTER TO && Reset FILTER TO to filter nothing. ENDDO * Clean up then bail objSession.Logoff RELEASE ojbRecip, objMessage, objSession ************ * END of * * SendMail * * routine. * ************One of the things I like about this code is that there is no AttachmentIndex and no AttachmentPosition to worry with.