I need email coding in c# using asp.net and also how change smtp settings in windows 7
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ramasagar PulidindiRank #163 · 14.4K reputationPosted Apr 5, 2014, 1:06 AM EDT
Ramasagar PulidindiRank #163 · 14.4K reputationPosted Apr 5, 2014, 1:09 AM EDT
Abhay ShankerRank #375 · 6.7K reputationPosted Apr 5, 2014, 3:15 AM EDT
pratik patel7 reputationPosted Apr 9, 2014, 4:08 AM EDT
In realtime we will use gmail,yahoo,hotmail etc to send mails to particular user here I will show to how to implement mail sending concept in asp.net.
To implement mail concept in asp.net first we need to add following reference to our applicationSystem.Web.Mail namespace
What is System.Web.Mail
System.Web.Mail is a namespace which contains classes that enable us to construct and send messages using the CDOSYS (Collaboration Data Objects for Windows 2000) message component. The mail message is delivered either through the SMTP mail service built into Microsoft Windows 2000 or through an arbitrary SMTP server.
How we can get this reference (System.Web.Mail)
We need to add System.web.dll reference to our application for that follow below steps
a a) On the Project menu, click Add Reference.
b) On the .NET tab, locate System.Web.dll, and then click Select.
c) Click OK in the Add References.
After that design your aspx page like this
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Send Mail using asp.nettitle>
head>
<body>
<form id="form1" runat="server">
<div>
<table style=" border:1px solid" align="center">
<tr>
<td colspan="2" align="center">
<b>Send Mail using asp.netb>
td>
tr>
<tr>
<td>
From:
td>
<td>
<asp:TextBox ID="txtFrom" runat="server">asp:TextBox>
td>
tr>
<tr>
<td>
Subject:
td>
<td>
<asp:TextBox ID="txtSubject" runat="server">asp:TextBox>
td>
tr>
<tr>
<td>
To:
td>
<td>
<asp:TextBox ID="txtTo" runat="server">asp:TextBox>
td>
tr>
<tr>
<td valign="top">
Body:
td>
<td>
<asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine" Columns="30" Rows="10" >asp:TextBox>
td>
tr>
<tr>
<td>
td>
<td>
<asp:Button ID="btnSubmit" Text="Send" runat="server" onclick="btnSubmit_Click" />
td>
tr>
table>
div>
form>
body>
html>
using System.Web.Mail;
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = txtFrom.Text;
// Recipient e-mail address.
Msg.To = txtTo.Text;
Msg.Subject = txtSubject.Text;
Msg.Body = txtBody.Text;
// your remote SMTP server IP.
SmtpMail.SmtpServer = "10.20.72.1";
SmtpMail.Send(Msg);
Msg = null;
Page.RegisterStartupScript("UserMsg", "");
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}