Hi...Have u ever thought of sending a mail with ASP.NET? Have u ever wondered how some sites uses automatic email delivary when u register for something? Here is the answer!!! emails can be sent through webpages by server side scripts!! Here I've given the pocedure to send mail with the help of ASP.NET...
The .NET framework library has a System.net.mail namespace. This namespace contains all the classes required to end a mail. For our purpose we will be using smtpclient and mailmessage class. We will also be using web.config file to configure the mail account settings.
Here is the code along with explanation.
---------------------------------------Web.Config file-------------------------------------
<!--Place the below code into the configuration tag in web.config
The usename and password used to logon and the smtp server address should be specified as attributes in network tag -->
<system.net>
<mailSettings>
<smtp>
<network port="465" userName="bharath87" password="xxxxxxxxx"
host="smtp.gmail.com"/>
</smtp>
</mailSettings>
</system.net>
----------------------------------Mail.aspx.vb------------------------------------
'when the aspx page loads the mail is sent to the recipent.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)_ Handles Me.Load
Dim mm As New System.Net.Mail.MailMessage("bharath87@gamil.com", "xxxx@gmail.com")
mm.Subject = "Test"
mm.Body = "This is a test message"
Dim smtp As New System.Net.Mail.SmtpClient()
smtp.Send(mm)
End Sub
-----------------------------------------------------------------------------------
As u can see, an instance of the Mailmessage class is created with all information about the mail (sender, recipent, subject, body of te mail etc.) specified through the properties and methods of he object.
A new smtpClient object is created. This object is used to send the mailmessage created to the recipent. When the send method is called ASP.NET contacts the smtp server specified in web.config and login to the server with the usrname and password provided(Web.config). Then the message is sent to the recipent through the smtp server.....
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment