|
Send Product Info Email With Pictures

The following script will email out information
on a stock item. It looks for and assumes the existence of a JPEG
image file that matches the product code name, followed by a .JPG
extension. The cPicPath variable should be set to point to a folder
holding pictures and this folder should be located on a shared path
that all users can access.
If the script is saved as STOCK1.MAC, it will
appear automatically under 'Tasks' on the user's Stock Control
menu. Multiple items may be emailed. If a stock item is tagged, the
tagged item will be sent. Multiple tags will result in the sending
of multiple stock items. If no tagging is set, the stock record
that is currently pointed to will be sent.
Users should select Edit|Clear Tags after sending
the email unless they want to send the same products and pictures
sent again.
This script especially demonstrates usage of the
TagInfo(),
AddMail(),
and
FormAdd()
functions.
*&Send Product Info with
Pictures
Declare cEmail Type
Character
Declare cSubject Type
Character
Declare cBody Type
Character
Declare aAttach Type
Array
Declare aTags Type
Array
Declare cPicPath Type
Character
Declare nCount Type
Number
Declare cCRLF Type
Character
Declare nErr Type
Number
cPicPath :=
"c:\pics\"
cEmail := ""
cSubject := "Product Information
From " + CompanyName(2)
nCount := 1
cCRLF := CHR(13) +
CHR(10)
cBody := "Thank you for requesting
information on our products." + cCRLF + cCRLF
aTags := {}
aAttach := {}
If TagInfo(3) == 0
If .Not.
IsFile(cPicPath + ALLTRIM(Stock->Name) + ".JPG")
Echo("Sorry, the
picture " + cPicPath + ALLTRIM(Stock->Name) + ".JPG could not be
found.")
Else
cBody := cBody +
"Product: " + Alltrim(Stock->Name) + " - " + Stock->Title +
cCRLF + cCRLF
AADD(aAttach,
cPicPath + ALLTRIM(Stock->Name) + ".JPG")
Endif
Goto
InputLoop
Endif
aTags := TagInfo(1)
:AddAttach
If .Not.
Stock->(Find(aTags[nCount,1], 3))
Echo("Could not
find stock item in tag buffer.",, TRUE)
Return
Endif
If .Not. IsFile(cPicPath +
Alltrim(Stock->Name) + ".JPG")
Echo("Sorry, the
picture " + cPicPath + Alltrim(Stock->Name) + ".JPG could not be
found.")
Return
Else
cBody := cBody +
"Product: " + Alltrim(Stock->Name) + " - " +
Alltrim(Stock->Title) + cCRLF + cCRLF
AADD(aAttach,
cPicPath + Alltrim(Stock->Name) + ".JPG")
Endif
nCount := nCount + 1
If nCount <=
LEN(aTags)
Goto
AddAttach
Endif
:InputLoop
FormCreate()
FormAdd("&Email", cEmail,
50)
FormAdd("&Subject", cSubject,
51)
FormAdd("&Body", cBody, { 51,
8 } )
If FormShow("Quick Catalog Send",
"Send", "Cancel")
cEmail :=
FormResult(1)
cSubject :=
FormResult(2)
cBody :=
FormResult(3)
If
IsEmpty(cEmail) .OR. .Not. "@" $ cEmail
Echo("Sorry, you
have not specified an email address or its formatting is
incorrect.",, TRUE)
Goto
InputLoop
Endif
If Len(aTags)
> 1
cBody := cBody +
"Photographs of these products are attached."
Else
cBody := cBody +
"A photograph of this product is attached."
Endif
AddMail(cEmail,
cSubject, cBody, aAttach)
nErr :=
SendMail()
If nErr #
0
Echo("Error
sending email: " + NTrim(nErr))
Endif
Endif
____________________________
Related Topics
CAPITAL Business
Script
Sample
Scripts
|