Sending Email Using ASP.NET Print

  • 5

Sending Email Using ASP.NET
Line No Coding
1 <%@ Page Language="VB" %>
2 <%@ Import NameSpace="System.Web.Mail" %>
3
12 myMail.Send(myMessage)
13 End Sub
14 // -->

 

Line No Explanation
1 Declare VB language is use as this page language
2 We need to import the component call System.Web.Mail,in order to use MailMessage object.
3 Declare the script language. Here, ASP.NET is using Visual Basic Language and this script is running at server side
4 This sub class will be called once the user click on the button
5 Create MailMessage Component
6 Create SMTP Mail Component
7 .From - To represent the sender
8 .To - To represent the recipient
9 .Subject - To represent the subject of the email
10 .Body - To represent the content of the email
11 .SMTPServer - represent SMTP server when sending

It is advisable to use SMTP server's IP address.

12 .Send - Send your message to the recipient
13 End of Sub class
14 End of script

Sample Coding:

<%@ Page Language="VB" %>
<%@ Import NameSpace="System.Web.Mail" %>
< script language="VB" runat="server">
Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
Dim myMessage As New MailMessage
Dim myMail As SmtpMail
myMessage.From = "sender email"
myMessage.To = "recipient email"
myMessage.Subject = "Subject of the email"
myMessage.Body = "Hello"
myMail.SmtpServer = "192.168.0.1"
myMail.Send(myMessage)
End Sub
// -->


Was this answer helpful?

« Back
© HostIcon. All rights reserved. Logo and name is a registered trademark of Space Technologies.