Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP information to the body of an email 1

Status
Not open for further replies.

SteveMacPSU

Programmer
Sep 8, 2005
32
US
I have an app where a user can type in a brief description of an activity in a table and then email that information to an outlook user. Here is what is in the record(a memo field).....

Hi,

Does this way work any better?

Please let me know, would you?

Dave & Steve

This is what gets into the body of the email...

Hi,Does this way work any better

Does anyone have any insight into why this text is being cut-off when it is sent to the body of the email.

This is how I format the email from the vfp9 record data:

cDes = TRIM(ACTIVITY.DESCRIPT)
cMail= "mailto:" + TRIM(ACTIVITY.TMAIL) + "&SUBJECT=SAM *** Request No " + TRIM(ACTIVITY.REQUESTNO) + "&Body= " + cDes
ShellExecute(0,"open",cMail,"","",1)

It appears to have a problem with ? and also with & and some other special characters.
 
create 2 local vevmars
lcQst = '?'
lcAmp = '&'

then use these memvars in the command line instead of the actual char and your problem will go away.


David W. Grewe Dave
 
Thanks for the quick answer Dave. The only problem is I have no idea what you are talking about. Could you dumb it down a little....

Steve
 
STORE "?" to lcQst
STORE "&" to lcAmp

cDes = TRIM(ACTIVITY.DESCRIPT)
cMail= "mailto:" + TRIM(ACTIVITY.TMAIL) + lcAmp+ "SUBJECT=SAM *** Request No " + TRIM(ACTIVITY.REQUESTNO) + lcAmp+"Body= " + cDes
ShellExecute(0,"open",cMail,"","",1)


David W. Grewe Dave
 
Steve,

I don't know if Dave's solution will work. I've not tried it myself.

The way I always do this is to insert the string "%0A" whereever I need a line break.

In other words, change this line:

cDes = TRIM(ACTIVITY.DESCRIPT)

to this line:

cDes = TRIM(STRTRAN(ACTIVITY.DESCRIPT, CHR(13), "%0A"))

That will automatically insert the required string at the end of each line, and the message should then be formatted correctly.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Dave,

Thanks again for the timely response, but that did not work. Mike your method got me the line breaks I needed but as soon as it hits a '?' it truncates the rest of cDes. If I take the '?' and '&' out of the memo field all is well.
 
Yep, I can see why My suggestion did not work,
I missed the fact you said in (Memo) and only looked at the code line.



David W. Grewe Dave
 
Steve,

I guess this is a limitation of using the ShellExecute() method to generate an email. The problem is that ? and & are being interpreted as mailto: delimiters, rather than as part of the message.

If this is likely to be a serious issue, you'll have to consider one the many other methods of creating emails, such as Automation or CDO.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Mike, I was afraid of that. I got the ShellExecute information from you. Do you have any recommendations on which of the two to use, remember I am slow, and where I might go to read up on them.
 
Hi,Does this way work any better "

The reason this is all in one line is there is no carriage return after the "Hi".

The way I would do this is to present the user with a Textbox for a Salutation ( Dear Sam) and an editbox (memo Field) for the body
Then when you are preparing the email:
Code:
cString = ""
cstring = altrim(textbox.value)+CHR(13)
cstring = cstring + alltrim(editbox.value)+chr(13)

oOutlook = Createobject('Outlook.Application')
oNameSpace = oOutlook.getnamespace('MAPI')
oOutbox = oNameSpace.GetDefaultFolder(4)
oItems = oOutbox.Items
oMailItem = oItems.Add(0)
oMailItem.To =  alltrim(ACTIVITY.TMAIL)	
oMailItem.Body = cString
oMailItem.Subject = "SAM *** Request "
oMailItem.ReadReceiptRequested = .T.
oMailItem.Display  &&&Send
 
Steve,

It just occurred to me that you don't have to use a different approach after all.

If ? and & are giving trouble, just change them to "%3F" and "%26" respectively (without the quotes). You can use STRTRAN() to do that, just as in my earlier example for getting rid of carriage returns.

Perhaps you could give that a try, and report back.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
You can replace any character in your mailtext with % plus it's asccii code in hexadecimal.

So try these stringtranslations:
Code:
cDes = ALLTRIM(ACTIVITY.DESCRIPT)
cDes = STRTRAN(cDes, CHR(10), "%0A"))
cDes = STRTRAN(cDes, CHR(13), "%0C"))
cDes = STRTRAN(cDes, "?", "%3F"))
cDes = STRTRAN(cDes, "&", "%26"))

This will urlencode "?", "&", line feed and carriage return characters. More general you need to URLencode the message to be able to use Shellexecute with "mailto:", as it's finally simply a URL you execute.

Bye, Olaf.
 
Imaginecorp,

That did the trick, thank you ever so much. That little problem has been driving me nuts for quite a while. Again, great forum guys and gals.
 
In the interest of science I went back and tried Mike and Olaf's recommendations. Alas, they also worked fine. It's nice to have so many experts at hand. I'm sure I'll come up with another stumper(for me) soon. Until then.....
 
I went back and tried Mike and Olaf's recommendations. Alas, they also worked fine.

Thanks for confirming that. Imaginecorp's solution via Outlook has the advantage of working with longer mail bodies too, but depends on Outlook. There are several other methods sending mails even without a mail client, just via internet connection using the SMTP protocol, which is nice if you can only be sure there is internet connection but not sure of anything else.

Here's an impressive list of possibilities


And I'm sure there are even much more possibilities to send mail.

Bye, Olaf.
 
Thank You. Glad I could help...

The code I posted earlier works for both Outlook and Outlook express.
If you want to use Only Outlook, the code is shorter and this is how you do it.

This assumes you have created the cString for the body.

The following checks if you have Outlook installed on the computer. You can also use this to check for Word, Excel etc. Just send the extension. Outlook = "OFT", doc, xls etc.

Code:
****** Must have registry program which ships with VFP in your path

Procedure checkforapplication(pExtension)
Local cExtn,cAppKey,cAppName,nErrNum,cNewKey
Local oReg,regfile,cVersion
cAppKey = ""
cAppName = ""
Set Procedure To registry Additive
oReg = Createobject("FileReg")
cExtn = Upper(pExtension)
* Get Application
nErrNum = oReg.GetAppPath(m.cExtn,@cAppKey,@cAppName)
If m.nErrNum # 0
	Return "No"
Endif
* Remove switches here (i.e., C:\EXCEL\EXCEL.EXE /e)
If Atc(".EXE",m.cAppName) #0
	m.cAppName= Alltrim(Substr(m.cAppName,1,Atc(".EXE",m.cAppName)+3))
	If Asc(Left(cAppName,1))=34	&&check for long file name in quotes
		m.cAppName = Substr(m.cAppName,2)
	Endif
Endif
Release Procedure registry
Return Iif(File(m.cAppName),"Yes","No")

Now before sending email:

Code:
Wait "Please wait while I check for Microsoft Outlook..." Window Nowait Noclear
cCheck = checkforapplication("OFT")
Wait Clear
If Alltrim(cCheck) = "No"
	=Messagebox("Unable to find Microsoft Outlook installed on your computer"+Chr(13)+;
		"Please notify your System Administrator",64,"Email")
	Return
Endif

loOutlook = Createobject('Outlook.Application')
Application.OLERequestPendingTimeout = 0
loMsg = loOutlook.CreateItem(0)
With loMsg
	.Recipients.Add(alltrim(ACTIVITY.TMAIL))
	.Subject = "SAM *** Request "
	***** For HTML
        *.BodyFormat = 2  && olFormatHTML
	*.HTMLBody = cString &&& could also use Filetostr()
	****************
        .body = cString
        .Display  &&&&& Send
Endwith
Release loMsg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top