You can try the solution in this site.
C# simplifies network programming in .Net framework. C# describes
various protocols using communication programming like Socket
communications , SMTP mail , UDP , URL etc. The System.Net classes
uses to communicate with other applications by using the HTTP, TCP,
UDP, Socket etc. In the previous program we saw how to SMTP email
from C# describes how to send an email with text body . Here we
are sending an email with an attachment.
Here is the sample code provided,
using System;
using System.Windows.Forms;
using System.Net.Mail;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("your_email_address@gmail.com");
mail.To.Add("to_address");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("your attachment file");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
You can also refer to the official .NET Quickstart from the documentation, here the in-depth discussion about the api was introduced together with sample code and step by step set-up process.
For further reference, you can visit this SO post.