Previous | Contents | Index |
Sheerpower includes a number of network-based extensions for accessing data from webpages and sending email.
open ch #num: name 'http[s]://url', timeout n |
Example 18-1 Accessing Data from Webpages |
---|
open #1: name 'http://www.ttinet.com/sheerpower/sample.txt', timeout 10 // try for no more then 10 seconds, then timeout for count = 1 to 100 line input #1, eof eof?: rec$ if eof? then exit for print count; tab(10); rec$ next count close #1 end |
To access raw HTML data from anywhere across the Internet.
The html:// file open option allows programs complete access to raw HTML data. This data can then be used to do things like get stock quotes, read news headlines, and fetch data from Sheerpower handlers.
You can also specify a timeout at the end of the open statement. The default length of time is 60 seconds if none is entered.
See Section 18.3, Webserver CGI Interface for more information.
email$ = 'mailto://' + sendto$ + '?subject=' + subject$ + '&mailfrom=' + mailfrom$ + '&replyto=' + replyto$ + '&friendlyname=' + friendlyname$ + '&cc=' + cc$ + '&server=' + servername$ + '&username=' + username$ + '&password=' + password$ + '&mime_type=html' open file email_ch: name email$, access output print #email_ch: 'Text of email.' print #email_ch: 'More text of email.' print #email_ch: 'End of email.' close #email_ch Where: sendto$ = email recipient subject$ = subject line mailfrom$ = who this email will claim it is from replyto$ = the "reply" email address if different from the "mailfrom$" address friendlyname$ = the display name seen by the recipient (i.e. From: "Support" <[email protected]>) cc$ = recipient to be copied on the email servername$ = SMTP server that handles outgoing emails username$ = SMTP server username (if outgoing authentication is required) password$ = SMTP server password (if outgoing authentication is required) mime_type=html = Defines the mime type of the email to allow sending HTML formatted emails |
Example 18-2 Sending Email |
---|
mailform$ = '<form>' mailform$ = mailform$ + 'From: <input type=text name=from ' + 'value="Sender email address"><br><br>' mailform$ = mailform$ + 'Reply To: <input type=text name=reply ' + 'value="Reply To email address"><br><br>' mailform$ = mailform$ + 'Friendly Name: <input type=text name=display ' + 'value="Friendly (display) Name"><br><br>' mailform$ = mailform$ + 'To: <input type=text name=to ' + 'value="Recipient email address"><br><br>' mailform$ = mailform$ + 'Server: <input type=text name=server ' + 'value="SMTP server name"><br><br>' mailform$ = mailform$ + 'Subject: <input type=text name=subject ' + 'value="Subject line"><br><br>' mailform$ = mailform$ + 'Text: <br><textarea name=body rows=5 cols=60>' mailform$ = mailform$ + 'Type in your text here.</textarea><br><br>' mailform$ = mailform$ + '<input type=submit name=submit value="Send Email">' mailform$ = mailform$ + '<input type=submit name=exit value="Cancel">' mailform$ = mailform$ + '</form>' line input dialogbox mailform$: data$ for item = 1 to pieces(data$, chr$(26)) z0$ = piece$(data$, item, chr$(26)) name$ = element$(z0$, 1, '=') value$ = element$(z0$, 2, '=') select case name$ case 'from' mailfrom$ = value$ case 'reply' replyto$ = value$ case 'display' friendlyname$ = value$ case 'to' sendto$ = value$ case 'server' servername$ = value$ case 'body' text$ = value$ case 'subject' subject$ = value$ case else end select next item email$ = 'mailto://' + sendto$ + '?subject=' + subject$ + '&mailfrom=' + mailfrom$ + '&replyto=' + replyto$ + '&friendlyname=' + friendlyname$ + '&server=' + servername$ + '&wait' message 'Sending...' open #1: name email$, access output print #1: text$ close #1 message 'Sent!' end |
To send emails.
When sending email, a number of optional parameters are supported.
cc | to copy another recipient to receive the email. To cc more than 1 recipient, use multiple CC options: &[email protected]&[email protected] | |
emailfrom | default to the value of sheerpower$emailfrom | |
replyto | to specify a "reply to" email address that is different from the emailfrom email address | |
friendlyname | the name that is displayed to the recipient beside your email address | |
server | default to the value of the logical sheerpower$server | |
wait | wait for email send to be completed | |
nowait | queue the email for sending as time permits | |
timeout | default is 30 second timeout. If we cannot reach the email server in this amount of time, abort the email sending. | |
username and password | when the SMTP server requires authentication, use these parameters to enter the username and password. | |
attach=file_to_attach.xxx | attach a file to this email. To attach more than one file, use multiple ATTACH options: attach=file1.xxx&attach=file2.xxx | |
mime_type=html | specifies the email can be created in HTML format. If this parameter is not defined, the default of plain text email will be used. |
The start of the parameter list begins with a ? (question mark), and each parameter is separated by an & (ampersand). |
Emails are queued for sending when the file is closed. If WAIT was specified, then Sheerpower waits until the email is delivered before continuing processing. The default is NOWAIT.
For high reliability on sending emails with Sheerpower, the SMTP server should be either on the same server as Sheerpower or at least on the same LAN. This is because the Sheerpower email handler is not a full email system that endlessly tries to send out emails even if the application has terminated.
The best use for the Sheerpower email facility is:
Sheerpower --> SMTP server (local one) --> Internet for delivery
This way there will be very few delays and reliability will be highest.
Sheerpower applications can easily be "web-enabled" through its simple CGI Interface. The CGI interface works with Sheerpower's own webserver program, SPINS webserver. For more information on SPINS webserver, see Chapter 17, Sheerpower Internet Services (SPINS) Webserver.
The sample CGI program eval_handler.spsrc is located in:
c:\sheerpower\sphandler |
The webpage instructions that go along with the sample program is located in the same folder, and is called cgi.html.
To use the CGI interface in Sheerpower, SPINS Webserver must be running. If the Microsoft IIS webserver is running, it needs to be stopped, or ports configured to run both webservers at the same time. Instructions are found here - Section 17.1.3, Specify a Different Port Number.
To continue with this test, double-click on the EVAL_HANDLER.SPSRC file. This runs the EVAL_HANDLER program. This program file is located in:
c:\sheerpower\sphandlers\eval_handler.spsrc
After the EVAL_HANDLER has been started, you can try the FORM below.
If this form did not work correctly for you, see Appendix L, Troubleshooting the CGI Interface. |
Previous | Next | Contents | Index |