Saturday, February 17, 2007

Sending Mail Using ASP.NET

Hi,
This is Simple Program To Send Mail to any Mail Id

using System.Web.Mail //Not Available in .NET 2005.

Control Name

From TextBox            = txtFrom
To TextBox                 = txtTo
Subject TextBox         =  txtSubject
Message TextBox       = txtMessage
MailStatus LabelBox  = lmailstatus



In your IIS Server You Have To Configure,

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

Program 

Protected Sub bSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bSend.Click
Dim msg As New Net.Mail.MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtMessage.Text)
Dim mOut As New Net.Mail.SmtpClient("127.0.01")
Try
mOut.Send(msg)
lmailstatus.Text = "Status Mail Sent"
Catch ex As Exception
lmailstatus.Text = ex.Message
End Try
End Sub

1 comment:

Joy said...

very useful coding
joy