Loading ...

How To Send Email In C Windows Forms Application

Hello everybody,

sometime people ask me how to send email from C# windows forms application or even ask is it possible at all to accomplish in C#?

I can reassure you that yes, it's possible. 

For this purpose you can use following code sample:

private void btnSendMessage_Click(object sender, EventArgs e)
{
            var from = new MailAddress(txtFrom.Text, "From Name");
            var toEmail = new MailAddress(txtTo.Text, "To Name");
            string passwordFromEmailOfSender = txtPassword.Text;
            string subject = "Subject";
            string body = txtMessage.Text;

            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(from.Address, passwordFromEmailOfSender)
            };
            using (var message = new MailMessage(from, toEmail)
            {
                Subject = subject,
                Body = body
            })
            {
                smtp.Send(message);
            }

}

 

If you'll execute program and fill some data you can see something like this:

SendEmailScreenshot.png

If your mailbox is from yahoo, you will see something similar to this:

SendEmailScreenshotResult.png

Also you can use presented code for making mass sending of some needed information for your business.

Ready to take your Acumatica development to the next level? Just as sending emails from a C# Windows Forms application can streamline your workflows, customizing Acumatica can unlock new efficiencies for your business. Whether you need tailored solutions, integrations, or unique features, our team is here to help.

Leave a customization request today and let’s build something extraordinary together! Your vision, our expertise—let’s make it happen.