Email Sending Code Form Server Side Asp.net
using System;
using System.Collections.Generic;
using System.Web;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
public partial class MAil : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
#region Remotehost
//--------FOR REMOTE HOST
try
{
if (Page.IsValid)
{
const string SERVER = "localhost";
MailMessage oMail = new MailMessage();
oMail.From = new MailAddress("contact@mail.co");
oMail.To.Add(new MailAddress("do_not_reply@mail.co"));
oMail.Subject = TextBox2.Text;
oMail.IsBodyHtml = true; // enumeration
oMail.Priority = MailPriority.High; // enumeration
oMail.Body = "<b>Sender's Name:-</b></b>" + TextBox1.Text + "<br/></b>" + "<b>Sender's Email:-</b></b>" + TextBox2.Text + "</b><br/>" + "<b>Sender's Mobile:-</b></b>" + TextBox3.Text + "</b><br/>" + "<b> Sender's Subject:-</b></b>" + DropDownList1.SelectedValue + "<br/></b>" + "<b>Sender's Message:-</b></b>" + TextBox4.Text + "<br/></b>" + "<b>Others:-</b></b>" + TextBox6.Text;
SmtpClient sC = new SmtpClient(SERVER);
sC.EnableSsl = false;
ContentType contentType = new ContentType();
contentType.MediaType = MediaTypeNames.Application.Octet;
contentType.Name = "xml.xml";
sC.Send(oMail);
oMail = null; // free up resources
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('EMail Sent');", true);
TextBox1.Enabled = false;
TextBox2.Enabled = false;
TextBox3.Enabled = false;
TextBox4.Enabled = false;
}
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Error Found');", true);
}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
public partial class MAil : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
#region Remotehost
//--------FOR REMOTE HOST
try
{
if (Page.IsValid)
{
const string SERVER = "localhost";
MailMessage oMail = new MailMessage();
oMail.From = new MailAddress("contact@mail.co");
oMail.To.Add(new MailAddress("do_not_reply@mail.co"));
oMail.Subject = TextBox2.Text;
oMail.IsBodyHtml = true; // enumeration
oMail.Priority = MailPriority.High; // enumeration
oMail.Body = "<b>Sender's Name:-</b></b>" + TextBox1.Text + "<br/></b>" + "<b>Sender's Email:-</b></b>" + TextBox2.Text + "</b><br/>" + "<b>Sender's Mobile:-</b></b>" + TextBox3.Text + "</b><br/>" + "<b> Sender's Subject:-</b></b>" + DropDownList1.SelectedValue + "<br/></b>" + "<b>Sender's Message:-</b></b>" + TextBox4.Text + "<br/></b>" + "<b>Others:-</b></b>" + TextBox6.Text;
SmtpClient sC = new SmtpClient(SERVER);
sC.EnableSsl = false;
ContentType contentType = new ContentType();
contentType.MediaType = MediaTypeNames.Application.Octet;
contentType.Name = "xml.xml";
sC.Send(oMail);
oMail = null; // free up resources
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('EMail Sent');", true);
TextBox1.Enabled = false;
TextBox2.Enabled = false;
TextBox3.Enabled = false;
TextBox4.Enabled = false;
}
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Error Found');", true);
}
}
No comments:
Post a Comment