sam samuel

sam samuel

  • 1.9k
  • 112
  • 3.7k

How to send mail from asp.net

Oct 5 2017 6:39 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;

namespace WebApplication2
{
public partial class ContactUs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Submit_Click(object sender, EventArgs e)
{
try
{
MailMessage msg = new MailMessage();
msg.To.Add("studenttrainer1@gmail.com");
MailAddress address = new MailAddress(txtEmail.Text);
msg.From = address;
msg.ReplyToList.Add(address);
msg.Subject = txtName.Text + " : " + txtSubject.Text;
msg.Body = txtDescription.Text;
SmtpClient client = new SmtpClient("smtp.gmail.com", 25);
client.EnableSsl = true;
NetworkCredential credentials = new NetworkCredential("studenttrainer1@gmail.com", "extentia");
client.Credentials = credentials;
client.Send(msg);
lblMessage.Text = "Your message was sent!";
txtEmail.Text = "";
txtSubject.Text = "";
txtName.Text = "";
txtDescription.Text = "";
}


catch
{
lblMessage.Text = "Your message failed to send, please try again.";
}
}
}
}
}
 
 
cant able to send mail from my website

Brought to you by:

Answers (7)