Wednesday, 23 January 2013


Not many users know that rebol has a ready to use interface for writing and sending email: emailer.
You have to put this command inside a layout to work it properly,otherwise it will stuck.

Here an example:
view layout [btn "click to launch emailer" [ emailer ]]

However you have to set your email information correctly. Usually when you launch viewtop for the first time, it asks your email settings.
If you want to change your email settings, just launch set-user, a wonderful pop-up will appear:

You probably noted that you can't set POP and SMTP passwords from set-user interface. Well, you can set them manually with 4 lines of code:

system/schemes/pop/user:   "my user name for POP"
system/schemes/pop/pass:   "mypassword for POP"
system/schemes/esmtp/user:   "my user name for SMTP"
system/schemes/esmtp/pass:   "mypassword for SMTP"

If you are a smart rebol user (and you are smart reading this blog), your next step will be to set this way:

system/schemes/pop/pass: func [] [request-pass/title/only "POP password?"]
system/schemes/esmtp/pass: func [] [request-pass/title/only "SMTP password?"]

In order to read your email message, just launch:

my-emails: read pop://

my-emails will be a block of string each string is an email message. Here a mailbox with just a message:
[ {Return-Path: <>
Received: from ( by (8.5.148)
        id 50F69CF201DA6639 for; Wed, 23 Jan 2013 12:42:03 +0100
Received: from ([])
^-by with
^-id rPi31k00l3qDwFD01Pi3fM; Wed, 23 Jan 2013 12:42:03 +0100
x-cnfs-analysis: v=2.0 cv=FraHDhXq c=1 sm=2 a=nDghuxUhq_wA:10
a=pGLkceISAAAA:8 a=yR1Yy4l2QB8A:10 a=bi5fCUJXM4t3MQuAs5MA:9 a=wPNLvfGTeEIA:10
a=oct3qPWNAAAA:8 a=djclfNPk0vczJORTAykA:9 a=bJZN8nw/mWW4J2Uhyp6xUg==:117
Received: by with SMTP id go11so2087218lbb.22
        for <>; Wed, 23 Jan 2013 03:41:47 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=20120113;
MIME-Version: 1.0
X-Received: by with SMTP id lm20mr1026251lab.42.1358941307899;
Wed, 23 Jan 2013 03:41:47 -0800 (PST)
Received: by with HTTP; Wed, 23 Jan 2013 03:41:47 -0800 (PST)
Date: Wed, 23 Jan 2013 12:41:47 +0100
Message-ID: <>
Subject: Prova rebol
From: Max Angel <>
Content-Type: multipart/alternative; boundary=f46d04374ee1ed8f5004d3f32dd2
Content-Type: text/plain; charset=ISO-8859-1
Testo di prova
Content-Type: text/html; charset=ISO-8859-1
Testo di prova<br clear="all"><br>-- <br><img src=""><br>

How to read it easily? There is the fantastic function import-email, look here:

>>mymessage: import-email my-emails/1
>> ? mymessage
mymessage is an object of value:
   To              block!    length: 1
   CC              none!     none
   BCC             none!     none
   From            block!    length: 1
   Reply-To        none!     none
   Date            date!     23-Jan-2013/12:41:47+1:00
   Subject         string!   "Prova rebol"
   Return-Path     string!   ""
   Organization    none!     none
   Message-Id      string!   {CAJ1MPLX2uj2OxCqUPrWrjvgwp76r832=TpV4qncGbV9wDje...
   Comment         none!     none
   X-REBOL         string!   "View http://WWW.REBOL.COM"
   MIME-Version    string!   "1.0"
   Content-Type    string!   {multipart/alternative; boundary=f46d04374ee1ed8f5...
   Content         string!   {--f46d04374ee1ed8f5004d3f32dd2 Content-Type: text...
   Received        block!    length: 4
   x-cnfs-analysis string!   {v=2.0 cv=FraHDhXq c=1 sm=2 a=nDghuxUhq_wA:10 a=pG...
   DKIM-Signature  string!   {v=1; a=rsa-sha256; c=relaxed/relaxed;
   X-Received      string!   {by with SMTP id lm20mr1026251lab.4...

So you can read your message easily:

with this code:

view layout [
    label "Subject:"
    text bold mymessage/subject
    label "From"    
    text form mymessage/from
    label "To:"
    text   form mymessage/to
    label "Date:"
    text   form mymessage/date
    box black 200x1
    do [   ;the following lines are to extraxt just the plain text version of the email message
        mex:   copy " "
        parse mymessage/content   [thru   "Content-Type: text/plain;" copy temp to " -- "   (append mex temp)]
        mex: remove (parse mex none)
    text   form mex

As you notice, making an email client with rebol is a breeze. (Image to use list in order to list all your emails, and your obtain an email client better than thunderbird... :-) )

1 comment:

  1. Nice article.

    In addition, I have enhanced the emailer window included in the viewtop to allow attachment.