In realtime we are going to use gmail,yahoo,hotmail etc to send mails to explicit user here i'll show to a way to implement mail causing idea in asp.net.
To implement mail idea in asp.net 1st we want to feature following relevancy our application System.Web.Mail namespace
What is System.Web.Mail
System.Web.Mail may be a namespace that contains categories that modify United States to construct and send messages exploitation the CDOSYS (Collaboration information Objects for Windows 2000) message part. The mail message is delivered either through the SMTP postal service designed into Microsoft Windows 2000 or through associate whimsical SMTP server.
How we will get this reference (System.Web.Mail)
We need to feature System.web.dll relevancy our application for that follow below steps
a) On the Project menu, click Add Reference.
b) On the .NET tab, find System.Web.dll, so click choose.
c) Click OK within the Add References.
After that style your aspx page like this
To implement mail idea in asp.net 1st we want to feature following relevancy our application System.Web.Mail namespace
What is System.Web.Mail
System.Web.Mail may be a namespace that contains categories that modify United States to construct and send messages exploitation the CDOSYS (Collaboration information Objects for Windows 2000) message part. The mail message is delivered either through the SMTP postal service designed into Microsoft Windows 2000 or through associate whimsical SMTP server.
How we will get this reference (System.Web.Mail)
We need to feature System.web.dll relevancy our application for that follow below steps
a) On the Project menu, click Add Reference.
b) On the .NET tab, find System.Web.dll, so click choose.
c) Click OK within the Add References.
After that style your aspx page like this
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Send Mail using asp.net</title>
</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.net</b>
</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", "<script>alert('Mail sent thank you...');if(alert){ window.location='SendMail.aspx';}</script>");
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}







0 comments:
Post a Comment