This example shows how to fill form data from database.
using var connection = new MySqlConnection("Server=YOURSERVER;User ID=YOURUSERID;Password=YOURPASSWORD;Database=YOURDATABASE");
await connection.OpenAsync();
using var command = new MySqlCommand("SELECT mail, recipient FROM table;", connection);
using var reader = await command.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
var mail = reader.GetString("mail");
var recipient = reader.GetString("recipient");
label.Text.Expression = $"Hello, {recipient}";
var pdf = pdfExporter.ExportForm(form);
var mailMessage = new MailMessage
{
From = new MailAddress("Diese E-Mail-Adresse ist vor Spambots geschützt! Zur Anzeige muss JavaScript eingeschaltet sein."),
Subject = "subject",
Body = "<h1>Hello</h1>",
IsBodyHtml = true,
};
mailMessage.To.Add(mail);
var attachment = new Attachment(new MemoryStream(pdf), MediaTypeNames.Application.Pdf);
mailMessage.Attachments.Add(attachment);
smtpClient.Send(mailMessage);
}