Name: <asp:TextBox ID="txtName" runat="server" /> Email: <asp:TextBox ID="txtEmail" runat="server" /> Message: <asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" /> <asp:Button ID="btnSubmit" runat="server" Text="Send Email" onclick="btnSubmit_Click" />
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.Net.Mail; protected void btnSubmit_Click(object sender, EventArgs e) { MailMessage message = new MailMessage(); message.To.Add("youremail@yahoo.com"); message.Subject = txtName.Text + " sent you a message via contact form"; message.From = new MailAddress(txtEmail.Text); message.Body = txtContent.Text; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.Credentials = new NetworkCredential("youremail@yahoo.com", "yourpassword"); client.EnableSsl = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Send(message); client.EnableSsl = true; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)