Yes,it is easy to send email in .Net application through SMTP Client.First you have add
using System.Net.Mail; namespace should be added in your application.
using System.Net.Mail; //namespace
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential("yourmailid@gmail.com", "yourgmailpassword");
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("fromemailid@gmail.com"iyen");
// Enable SSLsmtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = mailAuthentication;
////From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddressmessage.To.Add(Togmail@gmail.com);
message.Subject = "Test Mail from C# Application";
message.IsBodyHtml = false;
//// Message body content
message.Body = "Nice C# function"//// Send SMTP mail
smtpClient.Send(message);
MessageBox.Show("Email successfully sent.");
}
catch (Exception ex)
{
MessageBox.Show("Send Email Failed");
}
Before run this program check your are given
Vaild yourmailid@gmail.com , yourgmailpassword and vaild Togmail@gmail.com..
using System.Net.Mail; namespace should be added in your application.
using System.Net.Mail; //namespace
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential("yourmailid@gmail.com", "yourgmailpassword");
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("fromemailid@gmail.com"iyen");
// Enable SSLsmtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = mailAuthentication;
////From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddressmessage.To.Add(Togmail@gmail.com);
message.Subject = "Test Mail from C# Application";
message.IsBodyHtml = false;
//// Message body content
message.Body = "Nice C# function"//// Send SMTP mail
smtpClient.Send(message);
MessageBox.Show("Email successfully sent.");
}
catch (Exception ex)
{
MessageBox.Show("Send Email Failed");
}
Before run this program check your are given
Vaild yourmailid@gmail.com , yourgmailpassword and vaild Togmail@gmail.com..
No comments:
Post a Comment