Jump to content

Rebol Programming/send

From Wikibooks, open books for an open world

USAGE:

[edit | edit source]
SEND address message /only /header header-obj /attach files /subject subj /show 

DESCRIPTION:

[edit | edit source]

Send a message to an address (or block of addresses)

SEND is a function value.

ARGUMENTS

[edit | edit source]
  • address -- An address or block of addresses (Type: email block)
  • message -- Text of message. First line is subject. (Type: any)

REFINEMENTS

[edit | edit source]
  • /only -- Send only one message to multiple addresses
  • /header -- Supply your own custom header
    • header-obj -- The header to use (Type: object)
  • /attach -- Attach file, files, or [.. [filename data]]
    • files -- The files to attach to the message (Type: file block)
  • /subject -- Set the subject of the message
    • subj -- The subject line (Type: any)
  • /show -- Show all recipients in the TO field

SOURCE CODE

[edit | edit source]
send: func [
    {Send a message to an address (or block of addresses)} 
    address [email! block!] "An address or block of addresses" 
    message "Text of message. First line is subject." 
    /only "Send only one message to multiple addresses" 
    /header "Supply your own custom header" 
    header-obj [object!] "The header to use" 
    /attach "Attach file, files, or [.. [filename data]]" 
    files [file! block!] "The files to attach to the message" 
    /subject "Set the subject of the message" 
    subj "The subject line" 
    /show "Show all recipients in the TO field" 
    /local smtp-port boundary make-boundary tmp from
][
    make-boundary: does [] 
    if file? files [files: reduce [files]] 
    if email? address [address: reduce [address]] 
    message: either string? message [copy message] [mold message] 
    if not header [
        header-obj: make system/standard/email [
            subject: any [subj copy/part message any [find message newline 50]]
        ]
    ] 
    if subject [header-obj/subject: subj] 
    either none? header-obj/from [
        if none? header-obj/from: from: system/user/email [net-error "Email header not set: no from address"] 
        if all [string? system/user/name not empty? system/user/name] [
            header-obj/from: rejoin [system/user/name " <" from ">"]
        ]
    ] [
        from: header-obj/from
    ] 
    if none? header-obj/to [
        header-obj/to: tmp: make string! 20 
        if show [
            foreach email address [repend tmp [email ", "]] 
            clear back back tail tmp
        ]
    ] 
    if none? header-obj/date [header-obj/date: to-idate now] 
    if attach [
        boundary: rejoin ["--__REBOL--" system/product "--" system/version "--" checksum form now/precise "__"] 
        header-obj/MIME-Version: "1.0" 
        header-obj/content-type: join "multipart/mixed; boundary=" [{"} skip boundary 2 {"}] 
        message: build-attach-body message files boundary
    ] 
    smtp-port: open [scheme: 'esmtp] 
    either only [
        address: copy address 
        remove-each value address [not email? :value] 
        message: head insert insert tail net-utils/export header-obj newline message 
        insert smtp-port reduce [from address message]
    ] [
        foreach addr address [
            if email? addr [
                if not show [insert clear header-obj/to addr] 
                tmp: head insert insert tail net-utils/export header-obj newline message 
                insert smtp-port reduce [from reduce [addr] tmp]
            ]
        ]
    ] 
    close smtp-port
]