Method code for $smtp.sendmail()

[Turn on line numbering]
arg from, recip, subj, body;
var mailagent, header, c;

if (!.trusts(caller()) && !.trusts(sender()))
    throw(~perm, "Permission Denied: " + sender() + " is not trusted.");
mailagent = $motd.server_name() + " (" + ((| (.get_hosts_setting())[1] |) || "") + ":" + $login_daemon.current_port() + ")";
(> .parse_email_address(recip) <);
if (!from)
    from = 'postmaster;
if (type(from) == 'symbol)
    from = .get_email_address(from);
header = ["Date: " + $time.format("%a, %d %b %Y %H:%M:%S %Z"), "From: " + from, "To: " + recip, "Subject: " + subj, "Errors-to: " + .get_email_address('postmaster), "X-Mail-Agent: " + mailagent];

// connect to maildrop
c = (> .connect_to_smtp_host(maildrop) <);

// send it off
catch any {
    (> .MAIL_FROM(c, from) <);
    (> .RCPT_TO(c, recip) <);
    (> .DATA(c, header + [""] + body) <);
    (> .QUIT(c) <);
    .close_session(c);
} with {
    .close_session(c);
    rethrow(error());
}

// Created 13-Oct-1996 as a part of ColdCore, see: @help Credit

Tlon