Sending Email Through ASP.NET using VB

The following Sample Code is the code which can be used to send mails through ASP.Net VB.... its a working code for me.....

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Net.Mail

Public Partial Class [Default]
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
'Calling the function SendMail
Response.Write(SendMail("", "", "", "Test Mail", "Test Mail Body"))
End Sub

Public Function SendMail(ByVal toList As String, ByVal from As String, ByVal ccList As String, ByVal subject As String, ByVal body As String) As String
Dim message As New MailMessage()
Dim smtpClient As New SmtpClient()
Dim msg As String = String.Empty
Dim fromAddress As New MailAddress(from)
message.From = fromAddress
If ccList <> Nothing AndAlso ccList <> String.Empty Then
End If
message.Subject = subject
message.IsBodyHtml = True
message.Body = body
smtpClient.Host = ""
smtpClient.Port = 25
smtpClient.UseDefaultCredentials = True
smtpClient.Credentials = New System.Net.NetworkCredential("", "password")

msg = "Successful"
Catch ex As Exception
msg = ex.Message
End Try
Return msg
End Function

End Class

Thanks and Regards
Meetu Choudhary


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: