View Problem

Send an email

Use library functions, classes or objects to create a short email addressed to your own email address. The subject should be, "Greetings from langref.org", and the user should be prompted for the message body, and whether to cancel or proceed with sending the email.
ExpandDiskEdit
fantom
// read message body
echo("Enter message body. End the message with '.' character on a separate line:")
in := Env.cur.in
buf := StrBuf()
line := in.readLine;
while (line != null)
{
if (line.trim == ".")
break;
buf.add(line)
line = in.readLine
}

// construct email
email := Email
{
to = [ "someone@somewhere" ]
from = "me@mydomain"
subject = "Greetings from langref.org"
body = TextPart { text = buf.toStr }
}
mailClient := SmtpClient
{
host = "smtp.somewhere.net"
username = "me"
password = "my password"
log.level = LogLevel.debug
}

// send or abort
echo("Send email '$email.subject' to $email.to?: ");
line = in.readLine
echo("response=$line")
if (line?.trim.compareIgnoreCase("y") == 0)
mailClient.send(email)
else
echo("Aborted!")

Submit a new solution for fantom
There are 15 other solutions in additional languages (fsharp, groovy, haskell, java ...)