Add email capabilities to my app

The place to discuss FoxPro issues not directly related to ProMatrix.

Add email capabilities to my app

Postby btiguy » Sun Sep 15, 2013 11:20 am

I only find a short discussion about adding email capabilities to an app developed in VPM and it was from 3 years ago. I'm not very well educated about such topics. Can anyone lead me to some learning and how to add that capability? I have some old code, but it only works with Outlook. My clients may have any number of email applications, such as FireFox, etc.
TIA
Don
btiguy
 
Posts: 455
Joined: Mon Jun 21, 2010 4:03 pm

Re: Add email capabilities to my app

Postby Bob » Sun Sep 15, 2013 12:11 pm

This code will launch the User's default e-mail program ... the app's title will be the Subject.

I had this hard-coded to a government e-mail address in a button click event; you'll have to get your user's desired email address string into the correct place. Note there are no spaces after the colon in "mailto:" and none before or after the "?".

Has worked in win2k, XP, Vista, Win7 ... Hope this works for you!

** Automate user's e-mail client

EXTERNAL PROCEDURE ShellExec

jcSubjectLine=STRTRAN(_screen.oApp.cAppTitle,' ','%20')

tcWindow = 0 && 0 = desktop
tcOperation = "OPEN"
tcFileName = "mailto:"+<Your email string>+"?subject=" + jcSubjectLine + " Question"
tcParms = ''
tcDirectory = SYS(2023) && Local Temp folder
tcShowWin = 1

ShellExec(tcWindow, tcOperation, tcFileName, tcParms, tcDirectory, tcShowWin)



The ShellExec is a Windows API Call. Add this to the proapp.registerdllfunctions method:

DODEFAULT()

* DECLARE DLL for Shell functions.
DECLARE INTEGER ShellExecute IN SHELL32.DLL AS ShellExec ;
INTEGER nWindHAndle, STRING cOperation, STRING cFileName, ;
STRING cParameters, STRING cDirectory, INTEGER nShowWindow
Bob
 
Posts: 718
Joined: Mon Jun 14, 2010 6:53 am
Location: Near Albany, NY

Re: Add email capabilities to my app

Postby stecenko » Sun Sep 15, 2013 3:24 pm

You have to decide what 'email capabilities' means.

It can be s simple as launching the user's email client. Or it can be the automatic emailing of stuff from within your application.

For example, Report forms can ask the user if he or she wishes to email the pdf of the report. If yes, then the forms present a multi-select list of email addresses.

Or in an invoicing run, you can have invoices either emailed to the customer or printed depending on a flag set in the customer record.
Richard Stecenko
Interactive Computer Services Inc.
Victoria, British Columbia
204.453.2052
stecenko
 
Posts: 822
Joined: Mon Jun 21, 2010 8:06 pm
Location: Saanich, British Columbia

Re: Add email capabilities to my app

Postby billamidon » Sun Sep 22, 2013 10:29 am

I use CDO - the Sys_Main table contains the email settings, login, password, port, etc. You can hard code them for testing. I use the Google smtp servers.

Usually CDO is included in Office or Windows. If you need to install it try http://www.microsoft.com/en-us/download ... px?id=3671
* bc_CDOMail.prg
Parameters lcTo,lcAttach,lcReplyTo, lcSubject, lcBody
Local lcSchema, loConfig, loMsg, loError, lcErr, lnRecNo, lcAlias, lcTextBody
lnRecNo = Recno()
lcAlias = Alias()
If Vartype(lcReplyTo) = 'L'
lcReplyTo = Alltrim(Sys_Main.Ema_ClientReply)
Endif
If Vartype(lcAttach) = 'L'
lcAttach = ''
Endif
If Vartype(lcBody) = 'L'
lcBody = 'Body'
Endif
If Vartype(lcSubject) = 'L'
lcSubject = 'Subject'
Endif
If Vartype(lcTo) = 'L'
lcTo = ''
Endif


lcTextBody = lcBody
*Scan
If '@'$lcTo
Try
Local lcSchema, loConfig, loMsg, loError, lcErr
lcErr = ""
lcSchema = "http://schemas.microsoft.com/cdo/configuration/"
loConfig = Createobject("CDO.Configuration")
With loConfig.Fields
.Item(lcSchema + "smtpserver") = Alltrim(Sys_Main.Ema_SmtpPostOffice)
.Item(lcSchema + "smtpserverport") = Val(Sys_Main.Ema_SmtpPort) && 465 && ó 587
.Item(lcSchema + "sendusing") = 2
.Item(lcSchema + "smtpauthenticate") = .T.
.Item(lcSchema + "smtpusessl") = .T.
.Item(lcSchema + "sendusername") = Sys_Main.Ema_LoginClient
.Item(lcSchema + "sendpassword") = Sys_Main.Ema_PwClient
.Item(lcSchema + "replyto") = Sys_Main.Ema_ClientReply
.Item(lcSchema + "from") = Sys_Main.Ema_ClientReply
.Update
Endwith
lnRecNo = Recno()
loMsg = Createobject ("CDO.Message")
lcBcc = lcReplyTo
If Len(lcSubject) > 0
lcSubject = lcSubject + Space(1)
Endif
Wait Window 'Stand by..' Nowait
IF ! EMPTY(lcAttach)
loMsg.AddAttachment(Alltrim(lcAttach))
Endif
With loMsg
.BCC = lcBcc
.CC = lcReplyTo
.Configuration = loConfig
.ReplyTo = lcReplyTo &&Alltrim(Sys_Main.Ema_ClientReply)
.Sender = lcReplyTo &&Alltrim(Sys_Main.Ema_ClientReply)
.From = lcReplyTo &&Alltrim(Sys_Main.Ema_ClientReply)
.To = lcTo
.Subject = lcSubject
IF '</P>'$UPPER(lcTextBody) .or. '<HTML>'$UPPER(lcTextBody) .or. '<LI>'$UPPER(lcTextBody) .or. '<BR>'$UPPER(lcTextBody)

.HTMLBody = lcTextBody && Thisform.edtEma_batch3_note.Value
ELSE
.TEXTBody = lcTextBody && Thisform.edtEma_batch3_note.Value
Endif
.Send()
Endwith
Catch To loError
lcErr = [Error: ] + Str(loError.ErrorNo) + Chr(13) + ;
[Linea: ] + Str(loError.Lineno) + Chr(13) + ;
[Mensaje: ] + loError.Message
Finally
Release loConfig, loMsg
Store .Null. To loConfig, loMsg
If Empty(lcErr)
Wait Window 'Processing.... ' + Transform(Recno()) Nowait
Else
Messagebox(lcErr, 16 , "Error")
Endif
Endtry
Endif
*Endscan
Select(lcAlias)
Set Filter To
Go lnRecNo
Wait Window 'Finished Sending Email...' Nowait
billamidon
 
Posts: 122
Joined: Sun Jul 18, 2010 5:32 pm
Location: Mondovi, Wisconsin USA


Return to Visual FoxPro

Who is online

Users browsing this forum: No registered users and 2 guests

cron