using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net; using System.Net.Mail;
namespace Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnSennd_Click(object sender, EventArgs e)
{
string to, from, pass, mail;
to = (txtReceiver.Text).ToString();
from = (txtSender.Text).ToString();
mail = (txtMail.Text).ToString();
pass = (txtPassword.Text).ToString();
MailMessage message = new MailMessage();
message.To.Add(to);
message.From = new MailAddress(from);
message.Body = mail;
message.Subject = "Testing Mail";
SmtpClient smtp = new SmtpClient("smpt.gmail.com");
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(from, pass);
try
{
smtp.Send(message);
MessageBox.Show("Email sent successfully", "Email", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}