troubleshooting Question

Send emails from VFP app without Outlook

Avatar of woodwyn
woodwynFlag for United States of America asked on
FoxPro
5 Comments3 Solutions468 ViewsLast Modified:
We need to send emails from our VFP app. Currently we are calling outlook directly to do so using the following code. Ideally it would not depend on any external application and submit an email directly to a configured smtp server. If that is not an option using a generic interface that does not directly depend on outlook would still be useful. We do not need to receive email on these workstations, the mailing function should be as transparent to the user as possible, and not depend on outlook.   It will need to run on Windows Server 2012.

lnArea=SELECT()

lcBody = 'REQUEST DESCRIPTION: '+ALLTRIM(vSQLITRequests.Description)+CHR(13)+CHR(10)+CHR(13)+CHR(10)+;
			IIF(EMPTY(vSQLITRequests.Details),'','DETAILS: '+ALLTRIM(vSQLITRequests.Details)+CHR(13)+CHR(10)+CHR(13)+CHR(10))+;
			'CREATED AT: '+TTOC(vSQLITRequests.dtCreated)+CHR(13)+CHR(10)+;
			'CREATED BY: '+ALLTRIM(vSQLITRequests.CreatedBy)+CHR(13)+CHR(10)+;
			IIF(EMPTY(vSQLITRequests.ModifiedBy),'','MODIFIED AT: '+TTOC(vSQLITRequests.dtModified)+CHR(13)+CHR(10)+;
			'MODIFIED BY: '+ALLTRIM(vSQLITRequests.ModifiedBy)+CHR(13)+CHR(10))+;
			'REQUESTING EMPLOYEE: '+ALLTRIM(vSQLITRequests.RequestedBy)+CHR(13)+CHR(10)+;
			'REQUESTED COMPLETION ON OR BY DATE: '+DTOC(vSQLITRequests.dtRequestedComp)+CHR(13)+CHR(10)+;
			'PRIORITY: '+ALLTRIM(vSQLITRequests.Priority)+CHR(13)+CHR(10)+;
			'STATUS: '+ALLTRIM(vSQLITRequests.Status)+CHR(13)+CHR(10)+CHR(13)+CHR(10)+CHR(13)+CHR(10)
			
			
prmKeyITRequests=vSQLITRequests.keyITRequests
=REQUERY('vSQLITTasks')
SELECT vSQLITTasks

LOCATE
IF EOF()
	lcBody = lcBody + 'TO DATE NO TASKS HAVE BEEN COMPLETED FOR THIS REQUEST.'
ELSE
	lcBody = lcBody + 'TASKS COMPLETED FOR THIS REQUEST TO DATE:'+CHR(10)+CHR(13)+CHR(10)
	SCAN
		lcBody = lcBody +;
					'CREATED AT: '+TTOC(vSQLITTasks.dtCreated)+CHR(13)+CHR(10)+;
					'IT STAFF: '+ALLTRIM(vSQLITTasks.Staff)+CHR(13)+CHR(10)+;
					'TASK DESCRIPTION: '+ALLTRIM(vSQLITTasks.Description)+CHR(13)+CHR(10)+CHR(13)+CHR(10)
	ENDSCAN
ENDIF

SELECT (lnArea)

lcEmail=ALLTRIM(oLib.GetEmployeeEmail(vSQLITRequests.keyRequestedBy)) && Get the requestors email

loApp = CREATEOBJECT("Outlook.application")
loEmailItem = loApp.CreateItem(0)    && MAILITEM
loEmailItem.Recipients.Add("name1@domain.com")      &&Uses the Recipients collection
IF !EMPTY(lcEmail)
	loEmailItem.Recipients.Add(lcEmail)      &&Uses the Recipients collection
ENDIF
loEmailItem.Recipients.Add("name2@domain.com")      &&Uses the Recipients collection
loEmailItem.Subject = IIF(FinalEmail,"IT Request Final Notification","IT Request Notification")
loEmailItem.Importance = 1      && IMPORTANCENORMAL

loEmailItem.Body = lcBody

loEmailItem.Send

release loApp, loEmailItem
SOLUTION
Olaf Doschke
Software Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros