.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to send email

Posted By: Ramesh     Posted Date: November 25, 2008    Points:2   Category :ASP.Net
How to send Email in asp.net. Anyone please provide me the code to send email using C#.

Any Help would be appreciated.

Thanks
Ramesh

Responses
Author: Faizal             
Posted Date: November 26, 2008     Points: 5   

You can use System.Web.Mail.MailMessage or System.Net.Mail.MailMessage class to send mail


MailMessage objEmail = new MailMessage();
objEmail.To = abc@mail.com; //To Mail id
objEmail.From = xyz@mail.com; //From Mail Id
objEmail.Subject = "Test Email"; //Subject of the mail
objEmail.Body = "Anything in mail body"; //Mail Body
objEmail.Priority = MailPriority.High;
SmtpMail.SmtpServer = "localhost"; // Give you SMTP Server name
try{
SmtpMail.Send(objEmail);



Author: Akhil Raj       [Moderator]      
Posted Date: November 26, 2008     Points: 5   

Faizal gave the nice code for sending mail..

If you want some more information and smtp settings please review the following articles..


http://www.codeproject.com/KB/aspnet/EmailApplication.aspx
http://www.codeproject.com/KB/aspnet/EasySMTP_package.aspx


Author: Athira Sreejith             
Posted Date: December 31, 2008     Points: 5   

Hi..

Refer this code:

System.Web.Mail;

private void SendMail()
{
try
{
MailMessage m_newmail = new MailMessage();
SmtpClient s_client = new SmtpClient();
string attachfile=string.Empty;
Attachment m_attach;
string attachfile1=string.Empty;
string strdir = string.Empty;
MailAddress fromAdr = new MailAddress(txtEmail.Text);
m_newmail.From = fromAdr;

string strMailId = System.Configuration.ConfigurationManager.AppSettings["MailId"].ToString();
m_newmail.To.Add(strMailId);
m_newmail.Subject = "About Enquiry";

StringBuilder MailBody = new StringBuilder();
MailBody.Append("Name :" + txtName.Text.Trim() + "<br/>");
MailBody.Append("Designation :" + txtDesgntn.Text + "<br/>");
MailBody.Append("Company Name :" + txtCoName.Text + "<br/>");
MailBody.Append("Address :" + txtAddress.Text + "<br/>");
MailBody.Append("Pin :" + txtPin.Text + "<br/>");
MailBody.Append("Country :" + txtCountry.Text + "<br/>");
MailBody.Append("Telephone :" + txtTel1.Text + "-" + txtTel2.Text + "-" + txtTel3.Text + "<br/>");
MailBody.Append("Fax :" + txtFax.Text + "<br/>");
MailBody.Append("Like to comment on :" + cmbComment.SelectedValue + "<br/>");
MailBody.Append("Suggestions :" + txtSuggestions.Text + "<br/>");
MailBody.Append("Please tell us what you are looking for in enquiry :" + chklstEnquiry.SelectedValue + "<br/>");
MailBody.Append("Additional Information :" + txtAdditionalInfo.Text + "<br/>");
MailBody.Append("How did you here about us :" + cmbSelect.SelectedValue + " <br/>");

m_newmail.Body = MailBody.ToString();
m_newmail.IsBodyHtml = true;

if(fileName.HasFile)
{
attachfile = Path.GetFileName(fileName.PostedFile.FileName);
fileName.PostedFile.SaveAs(Server.MapPath(attachfile));

m_attach = new Attachment(Server.MapPath(attachfile));

m_newmail.Attachments.Add(m_attach);
attachfile1 = attachfile;
}
s_client.Host = "localhost";
s_client.UseDefaultCredentials = true;
s_client.Send(m_newmail);

ClientScript.RegisterClientScriptBlock(this.GetType(), "Hi!", String.Format("alert('An email has successfully been sent to {0}');", m_newmail.To), true);
ClearAll();

m_newmail.Dispose();

if (attachfile1 != null)
{
File.Delete(Server.MapPath(attachfile1));
}
}
catch (Exception ex)
{
ClearAll();
}
}

Author: krishana singh             
Posted Date: October 16, 2010     Points: 5   

protected void hrfSubmit_ServerClick(object sender, EventArgs e)
{
try
{
if (con.State == ConnectionState.Open)
con.Close();
con.Open();
string insertcontact = "INSERT INTO tblContactUs(Uname,Address,Mobile,Email,Comment) VALUES('" + txtname.Text + "','" + txtadd.Text + "','" + txtmobile.Text + "','" + txtemail.Text + "','" + txtcomment.Text + "')";
SqlCommand cmd = new SqlCommand(insertcontact,con);
cmd.ExecuteNonQuery();
txtadd.Text = txtemail.Text = txtemail.Text = txtcomment.Text = txtname.Text = txtmobile.Text = "";

string bodytext = "<html>";
bodytext += "<table border='1'>";
bodytext += "<tr><td>Name: </td><td>'" + txtname.Text + "'</td></tr><br/>";
bodytext += "<tr><td>EmailID: </td><td>'" + txtemail.Text + "'</td></tr><br/>";
bodytext += "<tr><td>Mobile:</td><td>'" + txtmobile.Text + "'</td></tr><br/>";
bodytext += "<tr><td>Address:</td><td>'" + txtadd.Text + "'</td></tr><br/>";
bodytext += "<tr><td>Comment</td><td>'" + txtcomment.Text + "'</td></tr><br/>";
bodytext += "</table>";
bodytext += "</html>";
Email.SendMail(txtemail.Text, "info@theflowersworld.com", "Contact information", bodytext);
Email.SendMail("info@theflowersworld.com", txtemail.Text, "confirmation mail", "your information saved successfully ");
}
catch (Exception ex)
{

txtadd.Text = txtemail.Text = txtemail.Text = txtcomment.Text = txtname.Text = txtmobile.Text = "";
}
}



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend