Quick Mail Coding in Asp.Net
- ) Use this name space
using System.Net;
using System.Net.Mail;
- ) Add this code in your button click:
MailMessage msg = new MailMessage();
msg.From = new MailAddress("sasigujai@gmail.com");
msg.To.Add("examples@gmail.com");
msg.CC.Add("examplej@gmail.com");
msg.Subject = "tst";
msg.Body = "<p> Name"+TxtboxID.Text+" </p>
<p>Last Name "+ TxtboxID.Text+"</p>
<p> Message "+ TxtboxID.Text+"</p> ";
<p>Last Name "+ TxtboxID.Text+"</p>
<p> Message "+ TxtboxID.Text+"</p> ";
msg.IsBodyHtml = true;
//*If you want to upload any fine
if (FileUpload1.HasFile)
{
msg.Attachments.Add(new Attachment
(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
}
SmtpClient smt = new SmtpClient();
smt.Host = "smtp.gmail.com";
System.Net.NetworkCredential ntwd = new NetworkCredential();
ntwd.UserName = "sasigujai@gmail.com"; //Your Email ID
ntwd.Password = "****** "; // Your Password
smt.UseDefaultCredentials = true;
smt.Credentials = ntwd;
smt.Port = 587;// Have to Command this line
smt.EnableSsl = true;
smt.Send(msg);
Response.Write("<script> alert('Email Sent Successfully')</script>");
No comments:
Post a Comment