Mail

Server Configuration

WithSMTPServerName and WithSMTPPortNum configure the outgoing mail server (default port 465). WithIMAPServerName and WithIMAPPortNum configure IMAP for receiving email (default port 993). WithPOPServerName and WithPOPPortNum configure POP3 for receiving email (default port 110). WithUserName and WithPassword set the authentication credentials. WithName sets the display name on whichever address was added just before it, so the same call names the sender or any recipient. LoadSettings() and SaveSettings() load and save all server settings to a file. With no argument both use ./GPALMail.yaml as the default path. Pass a GPALFile to redirect to a different path -- that path becomes the in-session default so subsequent no-arg calls use it automatically. WithAcceptAnyCertificate sends even when the server's certificate cannot be validated. Off unless a workflow asks, and it is for an internal relay with a certificate nobody signed, not for the internet.

NOTE

Receive reads from one incoming server, so WithIMAPServerName forgets any POP server and WithPOPServerName forgets any IMAP server. This matters because GPAL.Mail loads GPALMail.yaml when it is created: a stale file naming a POP server would otherwise decide the run. Whatever the code says explicitly comes after the load, so the code wins.

Examples

GPAL Fluent: High-level fluent C# API

//SaveSettings() and LoadSettings() persist and restore all server connection settings. With no argument both use ./GPALMail.yaml. Passing a GPALFile sets that path as the session default -- subsequent no-arg calls use it for the rest of the run.

// the mail object first, then the server settings and the envelope on it

IGPALMail mail = GPAL.Mail.ToGPALObject();


// Save server settings to the default path (./GPALMail.yaml)

mail

.WithSMTPServerName("smtp.example.com")

.WithSMTPPortNum(587)

.WithUserName("sender@example.com")

.WithPassword("app-password");


mail.SaveSettings();


// The display name belongs to an address, so it follows the address it names

mail

.WithFromEmailAddress("sender@example.com")

.WithName("GPAL Automation")

.WithToEmailAddress("ops@example.com")

.WithName("Operations");


// Redirect to a custom path -- becomes the session default

mail.SaveSettings((GPALFile)"config/mail.yaml");


// Load from the session-default path (no arg needed after redirect)

mail.LoadSettings();


// Or load and redirect in one call

mail.LoadSettings((GPALFile)"config/mail.yaml");

💬 Ask GPAL