Mail module

mail_send

procedure · 1 overloadSource

Sends msg through the SMTP server smtp and returns whether the server accepted it.

mail_send :: (smtp: Mail_Server, msg: Mail_Message) -> bool

The call blocks until the exchange is over, or until smtp.timeout_milliseconds has passed when that is set; with the default of 0 a stalled server is waited on for as long as libcurl allows. It does not retry and does not queue. Every failure returns false and logs one line through context.logger with the .ERROR flag: a header or host with a NUL, CR or LF (which would allow header injection), an empty recipient list, a port outside 0 to 65535, an attachment path that cannot be read, and anything libcurl or the server reports, in libcurl's wording. Environment proxies and .netrc files are ignored. The first call loads libcurl, so the Curl native library must be installed. Memory used during the call comes from temporary storage and is released before the call returns; the caller keeps ownership of everything it passed in.

Parameters

Returns

bool
ExampleOpen in playground ↗
smtp: Mail_Server;
smtp.host = "smtp.example.com";
smtp.port = 587;
smtp.enable_ssl = true;
smtp.username = "robot";
smtp.password = "secret";

message: Mail_Message;
message.from = "<[email protected]>";
message.to = .["<[email protected]>"];
message.subject = "Nightly build";
message.body = "The build finished.\r\n";

if !mail_send(smtp, message) print("could not send the report\n");

This one is only checked to compile, not run.