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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
pratik patelPosted Apr 9, 2014, 8:08 AM
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);
}
}
Abhay ShankerPosted Apr 5, 2014, 7:15 AM
Ramasagar PulidindiPosted Apr 5, 2014, 5:09 AM
Ramasagar PulidindiPosted Apr 5, 2014, 5:06 AM