Thursday 19 July 2012

Send E-Mail Code in ASP.Net


Send E-Mail Code in ASP.Net


Hello Friends,
Please follow below steps to send mail in ASP.net...

 
1) Create design page as below.





2. To prepare above UI follow this html code .
 
 
html xmlns="http://www.w3.org/1999/xhtml" >head runat="server">
</
<
<title>Untitled Page</title>head>body><form id="form1" runat="server"><div>
<asp:TextBox ID="txtname" runat="server" style="z-index: 100; left: 197px; position: absolute; top: 96px"></asp:TextBox><asp:TextBox ID="txtemailid" runat="server" style="z-index: 101; left: 197px; position: absolute; top: 130px"></asp:TextBox><asp:TextBox ID="txtmessage" runat="server" style="z-index: 102; left: 197px; position: absolute; top: 162px" TextMode="MultiLine"></asp:TextBox>&nbsp;<asp:Button ID="Btnsendmessage" runat="server" Text="Send" Width="70px" style="z-index: 103; left: 197px; position: absolute; top: 210px" />&nbsp;<asp:Label ID="lblmsg" runat="server" style="z-index: 104; left: 197px; position: absolute; top: 241px" ></asp:Label>
<asp:Label ID="Label1" runat="server" Style="z-index: 105; left: 133px; position: absolute;top: 96px" Text="Name"></asp:Label>
<asp:Label ID="Label2" runat="server" Style="z-index: 106; left: 133px; position: absolute;top: 130px" Text="Email ID"></asp:Label>
<asp:Label ID="Label3" runat="server" Style="z-index: 108; left: 133px; position: absolute;top: 162px" Text="Message"></asp:Label>
</div>
</
</
</form>body>html>

3. On Send Button's Click event put the below Code.

Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Web.Mail 

------------------------------------------------------------------------------------------ 
Protected Sub Btnsendmessage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btnsendmessage.ClickTryIf txtname.Text = "" Thenlblmsg.Text = "Mandatory field Name "txtname.Focus()
Exit SubEnd IfIf txtemailid.Text = "" Thenlblmsg.Text = "Mandatory field Email address"txtemailid.Focus()
Exit SubEnd IfIf txtmessage.Text = "" Thenlblmsg.Text = "Mandatory field Message address"txtmessage.Focus()
Exit SubEnd Ifsendmail()

Catch ex As ExceptionEnd Try
 
Sub
End Sub sendmail()If EMail() Thenlblmsg.Text = "Mail Send Succsessfully"txtname.Text = ""txtemailid.Text = ""txtmessage.Text = ""txtname.Focus()
End IfEnd Sub


Function EMail()Dim Emailid As String = txtemailid.TextDim Name As String = txtName.TextDim Receiver As String = txtemailid.Text 'Dim cc As String = ""Dim bcc As String = ""Dim subject As String = "Rajesh Somvanshi: Thanks For visit us."
Dim body As String = txtmessage.TextIf sendMail(Receiver, cc, bcc, subject, body) ThenReturn TrueElseReturn FalseEnd IfEnd FunctionPublic Function sendMail(ByVal Receiver As String, ByVal cc As String, ByVal bcc As String, ByVal subject As String, ByVal body As String) As IntegerTry

.From =
Dim mesg As New MailMessageWith mesg"Test@yahoo.com" ' Email Address.To = Receiver
.Cc =
"Test@yahoo.com".Bcc = "".Subject = "Rajesh Somvanshi: Thank For Visit us.".Priority = MailPriority.High
.Body = body
Dim creduser As String = mesg.From.ToString() ' Enter Your Email IDDim credpass As String = "Test8888888" 'Enter Your Password Here mesg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authenticationmesg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", creduser) 'set your username heremesg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", credpass) 'set your password hereSmtpMail.SmtpServer = "smtp.mail.yahoo.com" ' SMTP SERVER NAME.SmtpMail.Send(mesg)
End WithReturn True
Catch ex As ExceptionReturn FalseEnd TryEnd Function 
Note : - .Please Chanage the Email address with password.
 


Wednesday 18 July 2012

What is Difference between Function and Stored Procedure.?




Functions 
----------
1) can be used with Select statement
2) Not returning output parameter but returns Table variables
3) You can join UDF
4) Cannot be used to change server configuration
5) Cannot be used with XML FOR clause
6) Cannot have transaction within function


Stored Procedure
-----------------
1) have to use EXEC or EXECUTE
2) return output parameter
3) can create table but won’t return Table Variables
4) you can not join SP
5) can be used to change server configuration
6) can be used with XML FOR Clause
7) can have transaction within SP