Script Library: 1231 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

Documentation for: websend.r

Usage document for %websend.r

1. Introduction to %websend.r

websend.r is an introduction to the ease and simplicity of accessing the internet, and sending email.

2. websend At a Glance

Some setup is required. This script sends an email to, so you will need to edit this to a real email! address. It is also set to read the index page at You will need to edit the url! to read a page you are interested in sending to the email address you changed.

3. Using %websend.r

Requires REBOL/Core or REBOL/View console mode.

3.1. Standard REBOL settings

There is a standard utility that holds some basic REBOL configuration information. set-net takes a block of information so that REBOL knows how to route mail and for other internet connections. The REBOL/View Viewtop main User menu allows access to these settings or you can edit the default %user.r file and change the set-net information.

 >> help set-net
     SET-NET settings

      Network setup.  All values after default are optional.  Words OK for server names.
      SET-NET is a function value.

      settings -- [email-addr default-server pop-server
          proxy-server proxy-port-id proxy-type
          esmtp-user esmtp-pass] (Type: block)

The first two setting are for sending mail, the third is for reading mail, then there are proxy connection settings and then two settings for authenticated mail username and password.

3.2. Running %websend.r

Make a copy from the library with:

 >> write %websend.r read
The line above may look split, there is no carriage return if you type this in the console.

Edit this copy with your favourite editor, or if you are running REBOL/View use the builtin editor feature. Once you have changed the email! address and url! you are good to go. Just do it.

 >> do %websend.r

4. What you can learn

4.1. One of the many datatypes built into REBOL is email!. The REBOL system

knows that something @ something is a email address. The library script uses, but you'll want to change that to your own address.

Some early versions of REBOL do not directly support the newer ESMTP. The internal SEND utility in these older versions of REBOL may fail if your ISP requires Authenticated email transmission.

  • ESMTP -- Extended Simple Mail Transport Protocol

ESMTP is now in widespread use to fight spam. Older versions of REBOL fully support SMTP, but things have changed since mail servers started using the Extended AUTH verb to require password authentication before relaying mail. This is a good thing, and as of March 2007, most platforms have a REBOL release that supports ESMTP.

4.2. Powerful builtin Internet Access

REBOL has fantastically simple builtin procedures for accessing the internet.
read accesses and returns the HTML as text. How cool is that?

4.3. URLs is actually a value with a special datatype. In REBOL this is a url!. Very powerful. No quotes needed. REBOL just knows.

4.4. Web Server defaults

Web Servers have default files that are returned. is actually returned as This is not always the case. Some sites return default.htm, or index.php, or index.cgi. No need to worry, the REBOL read function and the web server will work that all out for you. If REBOL Technologies ever changes its web server setup, a different file may be returned and this script will still work.

4.5. Changing the page that is emailed

Changing the website or page that is sent is as easy as changing the text after the http:// part following the read command.

4.6. Getting REBOL

Both REBOL/Core and REBOL/View are available
free of charge from 

4.7. Compare the complexity to the simplicity

Please compare the print read 31 character sequence to this D language  program.

4.7.1. D Language sample for printing HTML as text

     HTMLget written by Christopher E. Miller
     This code is public domain.
     You may use it for any purpose.
     This code has no warranties and is provided 'as-is'.

 //debug = HTMLGET;

 import std.string, std.conv,;
 import std.socket, std.socketstream;

 int main(char[][] args)
     if(args.length < 2)
         printf("Usage:\n   htmlget <web-page>\n");
         return 0;
     char[] url = args[1];
     int i;

     i = std.string.find(url, "://");
     if(i != -1)
         if(icmp(url[0 .. i], "http"))
             throw new Exception("http:// expected");

     i = std.string.find(url, '#');
     if(i != -1) // Remove anchor ref.
         url = url[0 .. i];

     i = std.string.find(url, '/');
     char[] domain;
     if(i == -1)
         domain = url;
         url = "/";
         domain = url[0 .. i];
         url = url[i .. url.length];

     uint port;
     i = std.string.find(domain, ':');
     if(i == -1)
         port = 80; // Default HTTP port.
         port = std.conv.toUshort(domain[i + 1 .. domain.length]);
         domain = domain[0 .. i];

         printf("Connecting to " ~ domain ~ " on port " ~ std.string.toString(port) ~ "...\n");

     auto Socket sock = new TcpSocket(new InternetAddress(domain, port));
     Stream ss = new SocketStream(sock);

         printf("Connected!\nRequesting URL \" ~ url ~ "\"...\n");

     if(port != 80)
         domain = domain ~ ":" ~ std.string.toString(port);
     ss.writeString("GET " ~ url ~ " HTTP/1.1\r\n"
         "Host: " ~ domain ~ "\r\n"

     // Skip HTTP header.
     char[] line;
         line = ss.readLine();

         const char[] CONTENT_TYPE_NAME = "Content-Type: ";
         if(line.length > CONTENT_TYPE_NAME.length &&
             !icmp(CONTENT_TYPE_NAME, line[0 .. CONTENT_TYPE_NAME.length]))
             char[] type;
             type = line[CONTENT_TYPE_NAME.length .. line.length];
             if(type.length <= 5 || icmp("text/", type[0 .. 5]))
                 throw new Exception("URL is not text");

         line = ss.readLine();
         printf("%.*s\n", line);

         //if(std.string.ifind(line, "</html>") != -1)
         //  break;
         size_t iw;
         for(iw = 0; iw != line.length; iw++)
             if(!icmp("</html>", line[iw .. line.length]))
                 break print_lines;

     return 0;
What would you rather type? The above or
print read join http:// ask "Web site? " What will be easier to remember 6 months from now?

5. What can break

You will need access to the internet and will have to be up and running for this script to work. Don't worry, is always up and running.

6. Some Definitions

REBOL Relative Expression Based Object Language, pronounced as rebel.
HTML HyperText Markup Language.
HTTP HyperText Transport Protocol.
Web Common expression for World Wide Web, a term coined by Tim Berners-Lee in 1989.
www Abbreviation of World Wide Web.
URL Uniform Resource Locator, for naming things on the World Wide Web.
URI The Uniform Resource Identifier.
URN and the Uniform Resource Name, sometimes the U can stand for Universal.
url! REBOL's builtin URL datatype. REBOL just knows.

7. Also worth a look

There is a full suite of scripts that demonstrate how easy it is to use the HTTP url! (or "the web" ) features in REBOL.

These features are one of the central design goals of the REBOL scripting environment. These sample scripts highlight the ease of using internet resources with REBOL.

8. List of tutorial scripts in the web category

%webcheck.r  Determine if a web page has changed since it was last checked, and if it has, send the new page via email
%weblinks.r  Display all of the web links found on a page.
%webprint.r  Fetch a web page and display its HTML code.
%websend.r  Fetch a web page and send it as email.
%webfind.r  Search a web page for a string, and save the page.
%webtitle.r  Find the title of a web page and display it.
%webget.r  Fetch a web page and save it as a file.
%webfinder.r  Search multiple web pages for a string, and print the URL of the ones where it was found.
%web-to-plain.r  to translate htmlized text into plain text in one pass.
%webbanner.r  Generate HTML code that displays a banner and links to its destination.
%websplit.r  Separate the HTML tags from the body text of a document.
%webcam.r  style for webcam images
%webgetter.r  Fetch several web pages and save them as local files.
%oneliner-save-web-page-text.r  This line reads a web page, strips all its tags (leaving just the text) and writes it to a file called page.txt.
%countweb.r  Count the number of times a string appears on each of a given set of web pages.
%findweb.r  Simple example of searching multiple web pages for a specified string.
%timewebs.r  Time how long it takes to get each of the web pages listed in a block.
%webloop.r  Send a set of pages via email every hour.
%oneliner-webserver.r  Webserver serving files from the current directory.
%oneliner-print-web-page.r  Prints to the console the HTML source for a web page.

9. A script you have to check out

%oneliner-webserver.r  Webserver serving files from the current directory. A single line of REBOL code.

10. More in-depth scripts

%webcrawler.r  To crawl the web starting from any site. Does not record duplicate visits. Saves all links found in 'newlinks.
%extract-web-links.r  A function which scans a string (normally a web page) and creates a block of URL/Text combinations for each HTML <a> tag in the string.
%webserver.r  Here is a web server that works quite well and can be run from just about any machine. It's not only fast, but its also small so it's easy to enhance.
%webserv.r  A Simple HTTP-Server that can run REBOL CGI scripts
%volkswebserv.r  HTTP-Server for running and debugging REBOL CGI scripts, modified %webserv.r
%webwidget.r  Generate HTML code quickly and easily for several form elements.

10.1. Other web related scripts

dealing with web related REBOL programming that you can find in the library. There are also complete suites for FTP, HTML, CGI, and many others.
FTP related 
CGI related 
Email related 
Web related 

11. Credits

%webcheck.r Original author: Unknown
%weblinks.r Original author: Unknown
%webprint.r Original author: Unknown
%websend.r Original author: Unknown
%webfind.r Original author: Unknown
%webtitle.r Original author: Unknown
%webget.r Original author: Unknown
%webcrawler.r Original author: Bohdan Lechnowsky
%webfinder.r Original author: Unknown
%webserver.r Original author: Unknown
%web-to-plain.r Original author: Tom Conlin
%webbanner.r Original author: Andrew Grossman
%websplit.r Original author: Unknown
%webwidget.r Original author: Andrew Grossman
%webcam.r Original author: Piotr Gapinski
%webgetter.r Original author: Unknown
%oneliner-save-web-page-text.r Original author: Carl Sassenrath
%webserv.r Original author: Cal Dixon
%countweb.r Original author: Unknown
%findweb.r Original author: Unknown
%timewebs.r Original author: Unknown
%webloop.r Original author: Unknown
%extract-web-links.r Original author: Peter WA Wood
%oneliner-webserver.r Original author: Cal Dixon
%volkswebserv.r Original author: Cal Dixon, mods by Volker Nitsch
%oneliner-print-web-page.r Original author: Carl Sassenrath
REBOL/Core Carl Sassenrath, REBOL Technologies
REBOL/View Carl Sassenrath, REBOL Technologies
  • The Library Team
  • Usage document by Brian Tiffin, Library Team Apprentice, Last updated: 12-Jun-2007