using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net.Mail; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { MailMessage Mail = new MailMessage(); Mail.From = new MailAddress(textBox1.Text); Mail.To.Add(textBox3.Text); Mail.Subject = textBox4.Text; Mail.Body = textBox5.Text; if (textBox6.Visible == true) Mail.Attachments.Add(new Attachment(textBox6.Text)); SmtpClient smtp = new SmtpClient("smtp.gmail.com"); smtp.Port = 587; smtp.EnableSsl = true; smtp.Credentials = new System.Net.NetworkCredential(textBox1.Text, textBox2.Text); smtp.Timeout = 900000; smtp.Send(Mail); MessageBox.Show("send"); } catch (Exception ex) { throw ex; } } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { textBox6.Visible = true; OpenFileDialog open = new OpenFileDialog(); open.InitialDirectory = @"C:\"; open.Title = "Select file to Upload"; open.Filter = "All files (*.*)|*.*"; if (open.ShowDialog() == DialogResult.OK) { textBox6.Text = open.FileName.ToString(); } } } }