• DR-IT Software
  • Products
  • Documentation
  • Product page
  • Examples
  • API reference
  • Support
Show / Hide Table of Contents

Send Mail

Sends a mail message using an SMTP client.

Code

using DRIT.Mail.Rfc.Mime;
using DRIT.Mail.Rfc.Smtp;

// Build the message
var message = new MimeMessage
{
    Subject = "Test message",
};
message.From.Add(new MailboxAddress("sender@example.com", "Sender"));
message.To.Add(new MailboxAddress("recipient@example.com", "Recipient"));
message.Body = new TextPart("plain") { Text = "Hello via SMTP." };

// Configure the SMTP client
var options = new SmtpClientOptions
{
    Host = "smtp.example.com",
    Port = 587,
    SslMode = SmtpSslMode.StartTls,
    Credentials = new System.Net.NetworkCredential("user", "password"),
};

using var client = new SmtpClient(options);
client.Connect();
client.Authenticate();

SmtpDeliveryResult result = client.Send(message);
Console.WriteLine($"Accepted: {result.AcceptedRecipients}");
Console.WriteLine($"Rejected: {result.RejectedRecipients}");

client.Disconnect();

Remarks

SmtpClient supports plain, SSL, and STARTTLS connections. Authentication mechanisms include LOGIN, PLAIN, CRAM-MD5, and XOAUTH2 (see the Auth namespace).

  • Improve this Doc
Back to top

DR-IT Software documentation

DR-IT Software · Products · Documentation index · Product page · Downloads · Support · Licensing

Generated by DocFX