Modules

Mail

moduleSource
macOSLinuxWindowswasm

#import "Mail";

Sending email through an SMTP server, plus a small text obfuscation helper.

Fill in a Mail_Server and a Mail_Message and call mail_send, which delivers the message with libcurl and returns whether the server accepted it. It blocks until the exchange is over, reports failures through context.logger and its result rather than stopping the program, and borrows every string it is given. See mail_send for what is checked up front and how TLS is used. scramble is a reversible XOR mapping for keeping a string out of plain view; it is not encryption.

ExampleOpen in playground ↗
text := scramble("hunter2", "salt");
assert(scramble(text, "salt") == "hunter2");

Procedures#

Mail#

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

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

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.

Mail scramble#

(text: string, secret: string) -> string

Obfuscates text with secret and returns a string of the same length; running it again with the same secret gives the text back. This hides text from a casual look and is not encryption.

text := "Az 19!aZ0";
hidden := scramble(text, "A!z");

assert(hidden.count == text.count);
assert(hidden != text);
assert(scramble(hidden, "A!z") == text);
↗

Types#

:: struct

The SMTP server mail_send talks to, and how it logs in.