15. NS BASIC Tech Note

How to send email from NS BASIC -- February 14, 1996
----------------------------------------------------
Requirements: NS BASIC 3.x and Newton OS 2.0.

Sending email from NS BASIC is surprisingly easy. You can take virtually 
any
type of data that BASIC handles and route it to your Out Box. It can then 
be
sent out. The default carrier is eWorld.

This feature can be used for more than just sending messages to your 
friends.
You could also send data which is to be processed by other computers.

Here's some sample code:

0010 rem put a mail item into the out box
0020 LET transportSym:=getGroupTransport('mail)
0030 LET NSBSym:=getroot().|basic:nsbasic|
0040 LET item=getroot().(transportSym):newItem(NSBSym)
0050 LET item.toRef=[{name: "info",email:"info© nsbasic.com"}]
0060 LET item.title="NSBASIC info request"
0070 LET item.text="Please send me the latest info!"
0080 send('mail, item)

Here's what this program is doing:

Line 20 gets the name of the mail transport.
Line 30 gets the reference to NS BASIC.
In line 40, the newItem() function is called to set up a frame, customized 
for
mail from NS BASIC.
In lines 50-70, we customize that frame by adding some additional 
information:

 ToRef is an array of frames where mail is to be sent. Each frame has a 
name
and an email address. Multiple address can be specified.

 Title is the title of the message. Note that the first word of the title 
can
be used to signal how the Put Away function will handle the item: see the 
Tech
Note on "How to Handle Items in the In Box".

 Text is the text of the message.

 Body is not used in the above message, but can be used to enclose 
additional
information.

Finally, the send function in line 80 sends the item on its way.

For more information, see the Newton Programmer's Guide: Communications,
available on
http://devworld.apple.com/dev/newton/techinfo.html
Chapters 2 and 3 deal with transport
communications.