Create own application to send mail


Please find here how to send a mail from our own application. very simple 3 steps. 1.MailMessage, 2.NetworkCredential, 3.SmtpClient. Here I will explain how to send a mail from our own application. very simple 3 steps. 1.MailMessage, 2.NetworkCredential, 3.SmtpClient. Learn how to create code for own application to send mail.

How to create own application to send mail?


You can find here email application that has to be created and send by using the following code.

Email Application




private void btnSend_Click(object sender, EventArgs e)
{
string from=txtFrom.Text;
string pwd=txtPwd.Text;
string to = txtTo.Text;
string sub = txtSub.Text;
string body = txtBody.Text;
try
{
MailMessage mm = new MailMessage(fromId,to);
mm.Subject = sub;
mm.Body = body;
NetworkCredential nc = new NetworkCredential();
nc.UserName = fromId;
nc.Password = fromPwd;
SmtpClient sc = new SmtpClient();
sc.Host = "smtp.gmail.com";
sc.Port = 587;
sc.UseDefaultCredentials = false;
sc.Credentials = nc;
sc.EnableSsl = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Send(msg);
MessageBox.Show("Mail has been sent successfully","Info",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}


3 Steps to send mail
First Step

MailMessage mm = new MailMessage(fromId,to);
mm.Subject = sub;
mm.Body = body;

Second Step

NetworkCredential nc = new NetworkCredential();
nc.UserName = fromId;
nc.Password = fromPwd;

Third Step

SmtpClient sc = new SmtpClient();
sc.Host = "smtp.gmail.com";
sc.Port = 587;
sc.UseDefaultCredentials = false;
sc.Credentials = nc;
sc.EnableSsl = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Send(msg);


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: