using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Mail; using System.Net; public partial class Controls_ContactControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } protected void SendMail() { var fromAddress = "infosmbresidency@gmail.com";// Gmail Address from where you send the mail var toAddress = YourEmail.Text.ToString(); const string fromPassword = "*****";//Password of your gmail address string subject = YourSubject.Text.ToString(); string body = "From: " + YourName.Text + "\n"; body += "Email: " + YourEmail.Text + "\n"; body += "Subject: " + YourSubject.Text + "\n"; body += "Question: \n" + Comments.Text + "\n"; var smtp = new System.Net.Mail.SmtpClient(); { smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); smtp.Timeout = 20000; } smtp.Send(fromAddress, toAddress, subject, body); } protected void Button1_Click(object sender, EventArgs e) { try { SendMail(); lblMsgSend.Text = "Thanks For sending the mail"; lblMsgSend.Visible = true; YourSubject.Text = ""; YourEmail.Text = ""; YourName.Text = ""; Comments.Text = ""; } catch (Exception) { } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)