···2727 .optimize = optimize,
2828 });
2929 exe.addModule("smtp_client", smtp_client.module("smtp_client"));
3030-3130```
32313332# Basic Usage
···4544 .encryption = .none,
4645 .host = "localhost",
4746 .allocator = allocator,
4848- // .username="username",
4949- // .password="password",
4747+ // .username = "username",
4848+ // .password = "password",
5049 };
51505251 try smtp.send(.{
···6362* The message must be terminated with a `\r\n.\r\n` (yes, the dot in there is intentional)
64636564I plan on adding some type of `builder` to help with generating a valid `data` payload.
6666-67656866## Encryption
6967Prefer using `.encryption = .tls` where possible. Most modern email vendors provider SMTP over TLS and support TLS 1.3.
···76747775Regardless of the encryption setting, the library will favor authenticating via `CRAM-MD5` if the server supports it.
78767777+# Client
7878+The `send` and `sendAll` functions are wrappers around an `smtp.Client`. Where `send` and `sendAll` open a connection, send one or more messages and then close the connection, an `smtp.Client` keeps the connection open until `deinit` is called. The client is **not** thread safe.
7979+8080+```zig
8181+var client = try smtp.connect({
8282+ .port = 25,
8383+ .encryption = .none,
8484+ .host = "localhost",
8585+ .allocator = allocator,
8686+ // .username = "username",
8787+ // .password = "password",
8888+});
8989+defer client.deinit();
9090+9191+try client.hello();
9292+try client.auth();
9393+9494+9595+// Multiple messages can be sent here
9696+try client.from("email1@example.com");
9797+try client.to(&.{"recipient@example.com"});
9898+try client.data("From: Admin <email1@example.com>\r\nTo: User <recipient@example.com>\r\nSuject: Test\r\n\r\nThis is a test email from Zig\r\n.\r\n");
9999+100100+// One this is called, no more messages can be sent
101101+try client.quit();
102102+```
103103+104104+`hello` and `auth` can be called upfront, while `from`, `to` and `data` can be called repeatedly (protected by a mutex if thread-safety is needed).
105105+79106## Performance
80107### Tip 1 - sendAll
81108The `sendAll` function takes an array of `smtp.Message`. It is much more efficient than calling `send` in a loop.
···129156### Tip 3 - Skip DNS Resolution
130157Every call to `send` and `sendAll` requires a DNS lookup on `config.host`. The `sendTo` and `sendAllTo` functions, which take an `std.net.Address`, can be used instead. When using these functions, `config.host` must still be set to the valid host when `.tls` or `.start_tls` is used.
131158159159+Similarly, instead of `connect` to create a `Client`, `connectTo` can be used which takes an `std.net.Address`.
160160+132161### Allocator
133162`config.allocator` is required in two cases:
134134-1. `send` or `sendAll` are used, OR
163163+1. `send`, `sendAll` or `connect` are used, OR
1351642. `config.ca_bundle` is not specified and `.tls` or `.start_tls` are used
136165137166Put differently, `config.allocator` can be null when both these cases are true:
138138-1. `sendTo` or `sendAllTo` are used, AND
167167+1. `sendTo`, `sendAllTo` or `connectTo` are used, AND
1391682. `config.ca_bundle` is provided or `.encryption` is set to `.none` or `.insecure`.
140169141170Put differently again, `config.allocator` is only used by the library to (a) call `std.net.tcpConnectToHost` which does a DNS lookup and (b) manage the `std.crypto.Certificate.Bundle`.