protected string UserName = "******@gmail.com"; protected string Pass = "*******"; protected string MailRes = "*******@gmail.com"; protected void Button1_Click(object sender, System.EventArgs e) { using (MailMessage mailMessage = new MailMessage()) { string Msgsb = "\n Name : " + txt_name.Text.Trim() + "\n Address : " + txt_address.Text.Trim() + "\n Message : " + txtBody.Text.Trim(); mailMessage.From = new MailAddress(UserName); mailMessage.Subject = txtSubject.Text.Trim(); mailMessage.Body = Msgsb; mailMessage.IsBodyHtml = false; mailMessage.To.Add(new MailAddress(MailRes)); List<httppostedfile> files = (List<httppostedfile>)Session["Files"]; foreach (HttpPostedFile file in files) { mailMessage.Attachments.Add(new Attachment(file.InputStream, Path.GetFileName(file.FileName), file.ContentType)); Label1.Text = Label1.Text + file.FileName; } SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(); NetworkCred.UserName = mailMessage.From.Address; NetworkCred.Password = Pass; smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mailMessage); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)