lo = CREATEOBJECT("Outlook.application") >>>>...>>>>
TRY >> * Create our Outlook instance object >> loOutlook = CREATEOBJECT("outlook.application") >> llOutlookPresent = .t. >>CATCH >> llOutlookPresent = .f. >>ENDTRY >> >>* With Outlook we try to use it to send first >>llError = .f. >>IF llOutlookPresent >> TRY >> * Create our message >> loNameSpace = loOutlook.GetNameSpace("MAPI") >> loOutbox = loNameSpace.GetDefaultFolder(4) >> loNewMsg = loOutbox.Items.Add() >> >> * Append attachment (added for a simple example here, the logic actually may have multiple in a loop) >> loNewMsg.Attachments.Add(lcWhateverFile,1,1,"VisibleFilename.ext") >> * Note: See https: //msdn.microsoft.com/en-us/library/office/ff869553.aspx >> * Note: See https: //msdn.microsoft.com/en-us/library/office/ff868693.aspx >> >> * Populate content >> loNewMsg.Subject = ALLTRIM(this.Parent.subject.TextBox.Value) >> loNewMsg.Body = ALLTRIM(this.Parent.bodyText.EditBox.Value) >> thisForm.add_emails(loNewMsg, this.Parent.toAddy.TextBox.Value, 1) && 1=olTo >> >> * Add Cc: if need be >> IF NOT EMPTY(this.Parent.ccAddy.TextBox.Value) >> thisForm.add_emails(loNewMsg, this.Parent.ccAddy.TextBox.Value, 2) && 2=olCC >> ENDIF >> >> * Add Bcc: if need be >> IF NOT EMPTY(this.Parent.bccAddy.TextBox.Value) >> thisForm.add_emails(loNewMsg, this.Parent.bccAddy.TextBox.Value, 3) && 3=olBCC >> ENDIF >> >> * Try to resolve each email address >> FOR EACH loRecip IN loNewMsg.Recipients >> IF !loRecip.Resolve >> * On first failure, display the message in Outlook so they can resolve manually >> loNewMsg.Display >> >> * Raise an error >> llError = .t. >> lcMsg = "Error parsing email recipient. Please correct manually." >> EXIT >> ENDIF >> ENDFOR >> >> IF !llError >> * Send >> loNewMsg.Send() >> * If we get here, success >> ENDIF >> * Note: Depending on settings, the user may now have an unsent email >> * on their desktop waiting for them to manually click send. >> >> * Indicate an email was sent >> thisForm.lEmailSent = .t. >> >> CATCH >> llError = .t. >> lcMsg = "Unable to send email automatically using Outlook." >> ENDTRY >> >>ENDIF >> >>* Were we successful? >>IF llError OR NOT llOutlookPresent >> * Fallback method... >>ENDIF>