Sending Email Using ASP.NET

Line No Coding
1 <%@ Page Language="VB" %>
2 <%@ Import NameSpace="System.Web.Mail" %>
3 <script language="VB" runat="server">
4 Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
5 Dim myMessage As New MailMessage
6 Dim myMail As SmtpMail
7 myMessage.From = "sender email"
8 myMessage.To = "recipient email"
9 myMessage.Subject = "Subject of the email"
10 myMessage.Body = "Hello"
11 myMail.SmtpServer = "" <!-- replace with your server ip-->
12 myMail.Send(myMessage)
13 End Sub
14 </script>

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, please contact Exabytes Technical Support if you are not sure what is the correct IP to be used.

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

Sample Coding:

Add Feedback