#sh /usr/local/bin/rebol -s

Rebol [
    Title: "Envoi d'Email"
    Date:  12-apr-2001
    Version: 1.0.4
    File: %emailer.r
    Author: "Carl Sassenrath"
    Purpose: "A simple GUI example of an email sender."
    Email: carl@rebol.com
    Category: [email vid view 3 util]
]

lo: [
    style tx label 80x24 right
    style btn button 80x24
    style fld field 300x24
    origin 10x10
    vh4 "Envoi d'un mail :"
    across space 2x1
    tx "A:"      f-to: fld return
    tx "Et:"      f-cc: fld return
    tx "De:"    f-email: fld return
    tx "Sujet:" f-subject: fld return
    tx "Message:" f-msg: area wrap 300x200 return
    below at 10x256 space 0x4
    btn "Envoyer" #"^S" [submit]
    btn "Effacer" [clear-all]
    btn "Annuler" escape [close-em]
]

clear-all: does [
    clear-fields lo
    f-email/text: form system/user/email
    f-msg/line-list: none
    show lo
    f-to/text: "reziztanzia@free.fr"
    f-subject/text: "A propos de Rebol"
    focus f-msg
]

submit: does [
    sending: flash "Envoi..."
    either error? try [
        if empty? f-to/text [error-out-here]
        user: load/all f-to/text
        if not empty? f-cc/text [append user load/all f-cc/text]
        hdr: make system/standard/email [subject: f-subject/text]
        send/header user f-msg/text hdr
    ][
        unview/only sending
        request/ok "Erreur lors de l'envoi. Vérifiez vos paramètres."
    ][
        unview/only sending
        close-em
        request/ok "Votre mail a été envoyé"
    ]
]

close-em: does [unview/only lo]

set 'send-text func [
    "Ouvre un client mail"
    /to "Spécifiez une adresse mail"
    target [string! email!]
    /subject "Spécifiez un sujet"
    what [string!]
    /local req
][
    if block? lo [lo: layout lo  center-face lo none]
    if not all [system/user/email system/schemes/default/host] [
        req: request [{Vos paramètres de messagerie sont manquants.
            Editez les maintenant ?} "Editer" "Ignorer" "Annuler"]
        if none? req [exit]
        if req [set-user]
    ]
    clear-all
    if to [f-to/text: copy target]
    if subject [f-subject/text: copy what]
    focus f-msg
    view lo
]

either system/script/args [send-text/to system/script/args][send-text]