Friday, December 11, 2009

How to send an Email through Window Application with C#

private void btnSend_Click(object sender, EventArgs e)
{
string sTo = txtToEmailAddress.Text;
string sFrom = txtEmail.Text;
string sSubject = txtSubject.Text;
string sBody = txtBody.Text;

try
{
MailMessage mail = new MailMessage(sFrom, sTo, sSubject, sBody);
SmtpClient client = new SmtpClient("IP address");
client.Send(mail);
MessageBox.Show("Mail Successfully Sent");
txtSubject.Text = "";
txtEmail.Text = "";
txtBody.Text = "";
}
catch (Exception)
{
MessageBox.Show("Mail Sending Fail");
}
}

No comments: