Create and send email with attachment from ASP.NET with the GemBox.Email component using the Simple Mail Transfer Protocol (SMTP) in C# and VB.NET.

GemBox.Email is a .NET component that enables developers to compose, receive, and send email messages using the IMAP, POP, and SMTP protocols simply and efficiently from .NET applications.
You can use GemBox.Email for connecting to all major email providers. Also, it supports loading and saving emails, so you can store your emails exactly as they were received from the email server (with all of their headers and attachments).
GemBox.Email Free is free of charge, while GemBox.Email Professional is a commercial version that is licensed per developer.
For more information, see GemBox.Email Features or try our examples.

The following example demonstrates how to create and send an email message, with the attached sample file, by using the SmtpClient.

C# code

// Create new email message.
MailMessage email = new MailMessage(
    new MailAddress("""Sender"),
    new MailAddress("""Receiver"));
// Set email subject.
email.Subject = "Sending email from ASP.NET in C# and VB.NET";
// Set email body.
email.BodyText = "This message was created and sent from ASP.NET application by using GemBox.Email, a C# / VB.NET component!";
// Add attachment to email.
email.Attachments.Add(new Attachment(@"C:\ExampleAttachment.txt"));
// Create SMTP client.
using (SmtpClient smtp = new SmtpClient("<ADDRESS>"))
    // Connect and login to email server.
    // Send an email message.

VB.NET code

' Create new email message.
Dim email As New MailMessage(
    New MailAddress("""Sender"),
    New MailAddress("""Receiver"))
' Set email subject.
email.Subject = "Sending email from ASP.NET in C# and VB.NET"
' Set email body.
email.BodyText = "This message was created and sent from ASP.NET application by using GemBox.Email, a C# / VB.NET component!"
' Add attachment to email.
email.Attachments.Add(New Attachment("C:\ExampleAttachment.txt"))
' Create SMTP client.
Using smtp As New SmtpClient("<ADDRESS>")
    ' Connect and login to email server.
    ' Send an email message.
End Using