
smtp.pl -- Send E-mail through SMTPThis module provides a simple means to send E-mail from a Prolog application. Here is a simple example:
send_message(Out) :-
format(Out, 'Hi Alice,\n\n', []),
format(Out, 'Want to go out tonight?\n\n', []),
format(Out, '\tCheers, Bob\n', []).
?- smtp_send_mail('alice@wonderland.com',
send_message,
[ subject('Tonight'),
from('bob@wonderland.com')
]).
This library currently supports good old SMTP, encrypted and authorized
ESMTP. Both SSL/TLS and STARTTLS encryption is supported. Authorization
is supported using =PLAIN= and =LOGIN= methods.
Data is currently being sent using the =DATA= keyword.
@tbd Support more advanced data transport extensions such as sending
MIME messages.
smtp_send_mail(+To, :Goal, +Options)smtp(+Host)
the name or ip address for smtp host, eg. swi-prolog.orgfrom(+FromAddress)
atomic identifies sender address. Provides the default
for header(from(From)).date(+Date)
Set the date header. Default is to use the current time.subject(+Subject)
atomic: text for 'Subject:' email headerauth(User-Password)
authentication credentials, as atoms or strings.auth_method(+PlainOrLoginOrNone)
type of authentication. Default is default, alternatives
are plain and loginsecurity(Security)
one of: none, ssl, tls, starttlscontent_type(+ContentType)
sets Content-Type headermailed_by(By)
add X-Mailer: SWI-Prolog <version>, pack(smtp) to header
iff By == trueheader(from('My name,
me@server.org')) adds header "From: My name, my@server.org"
and header('FOO'(bar)) adds "FOO: bar"Defaults are provided by settings associated to this module.
Listens to debug(smtp) which for instance reports failure to
connect, (computation fails as per non-debug execution).
hostname(-HostName, +Options) is det[private]
do_send_mail(+In, +Out, +To, :Goal, +Options) is det[private]Note that HELO is the old SMTP greeting. Modern systems greet using EHLO, telling the other side they want to speak RFC 1870 rather than the old RFC 821.
starttls(+In0, +Out0, -In, -Out, +LinesIn, -LinesOut, +Options)[private]
auth(+In, +Out, +From, +Lines, +Options)[private]plain and login authentication methods. Authorization is
sent if the option auth is given or the settings user and
password are not the empty atom ('').
auth_supported(+Lines, -Supported)[private]
sock_send(+Stream, +Format, +Args) is det[private]format(Format, Args) to Stream and flush the
stream.
header_options(+Out, +Options) is det[private]header(from(From)) it uses the from(From)
from Options.date(Spec) it adds date(Date).
read_ok(+Stream, ?Code) is semidet[private]
read_ok(+Stream, ?Code, -Lines) is semidet[private]
read_ok(+Stream, ?Code) is semidet[private]
read_ok(+Stream, ?Code, -Lines) is semidet[private]