<1> IMPORT LIBRARIES >> TO FORM(or ASPX page ) & CLASS
using System.Net.Mail;
<2>INCLUDE CLASS BELOW
class sendmail
{
public void testmail(string to,string subject,string body)
{
try
{
string To=to;
string sub=subject ;
string Body=body ;
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("absccd@gmail.com");
// email adress that i have created on gmail
// or you can use any mail server such as yahoo,aol,msn,and so on
mail.To.Add(To);
mail.Subject = sub;
mail.Body = Body;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("userNAme", "Password");
//enter uname and pwd of email address you want to send email from
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Sent successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
<3>CREATE OBJECTS FROM THAT(in the form or page) and USE IT
sendmail obj = new sendmail();
obj.testmail(toContentTextBox.Text, subjectContentTextBox.Text, messageContentTextBox.Text);
//enjoy your program
[contact-form subject='[KLC%26#039;s knowledge SharePoint'][contact-field label='Name' type='name' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='Website %26#x002c;Links %26#x002c;Profiles(facebook%26#x002c;g+..etc) ' type='url'/][contact-field label='Comment' type='textarea' required='1'/][contact-field label='other ?' type='text'/][/contact-form]
Comments
Post a Comment