Sending Mail Using System.Net.Mail
This Is the Simple program to Send Mail Using System.Net.Mail using ASP.NET 2.0
Code Behind
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
using System.Drawing;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ }
}
protected void btSend_Click(object sender, EventArgs e)
{
try
{
MailMessage mM = new MailMessage();
mM.From = new MailAddress(txtFrom.Text);
mM.To.Add(txtTo.Text);
mM.Subject = txtSub.Text;
mM.Body = txtMsg.Text;
mM.IsBodyHtml = true;
mM.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("smtp.mail.yahoo.com");
sC.Port = 587;
sC.Credentials = new NetworkCredential("YahooId", "Yahoo Password");
//sC.EnableSsl = true;
sC.Send(mM);
lbReport.Text = "Mail Send Successfully";
lbReport.ForeColor = Color.Green;
}
catch(Exception ex)
{
lbReport.Text = ex+"Mail Sending Fail's";
lbReport.ForeColor = Color.Red;
}
}
}
InlineCode
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 526px">
<tr>
<td style="width: 116px; height: 26px;">
<strong>From</strong></td>
<td style="width: 324px; height: 26px;">
<asp:TextBox ID="txtFrom" runat="server" Width="391px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 116px; height: 26px;">
<strong>To</strong></td>
<td style="width: 324px; height: 26px;">
<asp:TextBox ID="txtTo" runat="server" Width="392px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 116px">
<strong>Subject</strong></td>
<td style="width: 324px">
<asp:TextBox ID="txtSub" runat="server" Width="394px"></asp:TextBox></td>
</tr>
<tr>
<td style="height: 290px">
<strong>Message</strong></td>
<td style="height: 290px; width: 324px;">
<asp:TextBox ID="txtMsg" runat="server" Height="284px" TextMode="MultiLine" Width="394px"></asp:TextBox></td>
</tr>
<tr>
<td style="height: 5px">
</td>
<td style="width: 324px; height: 5px">
<asp:Button ID="btSend" runat="server" Text="Send" OnClick="btSend_Click" /> <asp:Button
ID="btClear" runat="server" Text="Clear" /></td>
</tr>
</table>
</div>
<asp:Label ID="lbReport" runat="server" Font-Bold="True" Font-Names="Times New Roman"></asp:Label>
</form>
</body>
</html>
In your IIS Server You Have To Configure, When there is an need for this,
Step As Follow,
Step 1: Default SMTP Virtual Server.
Step 2:Right-click it.
Step 3:Select Properties.
Step 4:Select Access tab.
Step 5:Click Relay Button.
Step 6:Relay Restriction Dialog Box, only the list below Option Will Be Selected By Default.
Step7:If The local IP address: 127.0.0.1 is Entered Means leave that one else you have to add the above ip address in The Single Computer Ip address it's enough.
By windows mss Popularity (22397 Views)