Mail

Composing Messages

WithFromEmailAddress sets the sender address as a string or MailboxAddress object. WithToEmailAddress, WithCcEmailAddress, and WithBccEmailAddress set recipients - each accepts a single address string, a MailboxAddress, or a string array for multiple recipients. WithSubject sets the subject line. WithBody sets the message body text. WithAttachment adds a file attachment by GPALFile reference. Multiple WithToEmailAddress calls can be chained to add recipients one at a time, or pass a string array to add them all at once.

Examples

GPAL Fluent: High-level fluent C# API

//Chain all configuration before calling Send(). Each call returns the same IGPALMail instance so the chain stays fluent. WithAttachment can be called multiple times to attach multiple files.

// Compose and send a message

GPAL.Mail

.WithSMTPServerName("smtp.example.com")

.WithSMTPPortNum(587)

.WithUserName("sender@example.com")

.WithPassword("pass")

.WithFromEmailAddress("sender@example.com")

.WithToEmailAddress("recipient@example.com")

.WithCcEmailAddress(new[] { "cc1@example.com", "cc2@example.com" })

.WithSubject("Automated Report - 2026-06-08")

.WithBody("Please find the attached report.")

.WithAttachment("report.pdf")

.Send();

💬 Ask GPAL