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("Адрес электронной почты защищен от спам-ботов. Для просмотра адреса в браузере должен быть включен Javascript."),
		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);
}

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.