*********** PROCEDURE CdoEmail *-Send Emails using CDO PARAMETER ; cSMTPServer ,; nSMTPPort , cAcctName , CSMTPEmail ,; nAuthenticate, cUserName , cPassword ,; cSSL , nSendUsing ,; cTo , cFrom , cCc ,; cBCC , cSubject , cTextBodyType ,; cTextBody , cAttachment DECLARE SHORT InternetGetConnectedState In wininet.Dll; INTEGER @lpdwFlags, Integer dwReserved LOCAL ; lCont , lConnect, iMsg ,; iConf , Flds STORE .t. TO ; lCont , lConnect *-Check for an Internet Connection lConnect=This.displayState() IF NOT lConnect = MESSAGEBOX("Unable to send email. No internet connection found. ", 16, "CDO Email Automation") ELSE iMsg = Createobject("CDO.Message") iConf = Createobject("CDO.Configuration") Flds = iConf.Fields WITH Flds *-Check the following link for detailed help on the CDO Schemas *http://msdn2.microsoft.com/en-us/library/ms872380.aspx .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = cSMTPServer && Ex. 'smtp.atlga.adelphia.net' IF EMPTY(nSMTPPort) *-TCP Port for SMTP Server - Most SMTP Servers use port 25 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 ELSE .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = nSMTPPort ENDIF IF NOT EMPTY(cAcctName) *-Account Name is only required if the SMTP "server requires authentication". .Item("http://schemas.microsoft.com/cdo/configuration/smtpaccountname") = cAcctName &&"myaccount@server.com" ENDIF IF NOT EMPTY(cSMTPEmail) *SMTP Email Address is only required if SMTP "server requires authentication". .Item("http://schemas.microsoft.com/cdo/configuration/smtpemailaddress") = cSMTPEmail &&"myaccount@server.com" ENDIF IF NOT EMPTY(nAuthenticate) && Defaults to 0 - Anonymous *Anonymous (0) will work in most cases, unless the SMTP "server requires authentication". If you are using Exchange Server on a Domain, you may require *- NTLM (2). Otherwise, use Basic Text (1). .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = nAuthenticate &&0-Anonymous;1 -Basic Text;2-NTLM ENDIF IF NOT EMPTY(cUserName) *-UserName and Password is only required if the SMTP "server requires authentication". .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = cUserName &&"myaccount@server.com" ENDIF IF NOT EMPTY(cPassword) *-UserName and Password is only required if the SMTP "server requires authentication". .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = cPassword ENDIF IF cSSL = "YES" && Defaults to False *-Only required if the SMTP server requires SSL connection. .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = .t. ENDIF IF NOT EMPTY(nSendUsing) && Defaults to 2 (SendUsingPort) *-In most cases, the default of 2 (SendUsingPort) will work here. *-If you are running Exchange Server, you may need to use 3 (SendUsingExchange). .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = nSendUsing &&2 - SendUsingPort 3- SendUsingExchange 1-SendUsingPickup ENDIF *-Default is 30 Seconds .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 && in Seconds *-Note: The following are specific setings for a Gmail Account: *.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com", *.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")= 465 && Gmail uses port 465 *.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "account@gmail.com" && Enter your account name here *.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "accountpassword" && Enter your password here *.Item("http://schemas.microsoft.com/cdo/configuration/smtpaccountname")="account@gmail.com" && Enter your account name here *.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = .t. && Gmail requires SSL .Update() ENDWITH WITH iMsg .Configuration = iConf .To = cTo .CC = cCC .BCC = cBCC .From = cFrom .Subject = cSubject DO CASE CASE cTextBodyType = "SINGLE_LINE_PASSIN" .TextBody = cTextBody CASE cTextBodyType = "IMPORT_TEXT_FROM_FILE" CREATE CURSOR d_import (memofld M) APPEND BLANK APPEND MEMO memoFld FROM &cTextBody. .TextBody = d_import.memofld USE IN SELECT("d_import") OTHERWISE .TextBody = "*" ENDCASE IF NOT EMPTY(cAttachment) AND FILE(cAttachment) .AddAttachment(cAttachment) ENDIF .Send() ENDWITH iMsg = .Null. iConf = .Null. ENDIF RETURN *********** PROCEDURE displayState LOCAL lConnected lConnected = .F. lpdwFlags = 0 *-The following is a function in VFP 8 and greater IF InternetGetConnectedState (@lpdwFlags, 0) = 1 lConnected = .T. ENDIF RETURN lConnected