Kuzhikkattil

Just another WordPress.com weblog

Mail ,GetBodyAsHtml,GetToList from Db

Private Function GetBodyAsHtml(ByVal Bodytext As String, ByVal HeaderText As String, ByVal FooterText As String) As String
Dim sb = New System.Text.StringBuilder

sb.Append(“Tasks”)
sb.Append(“

“)
sb.Append(“
“)
sb.Append(“
“)
sb.Append(“

“)
sb.Append(“

“)
sb.Append(“

“)
sb.Append(“

” & HeaderText & “

“)
sb.Append(Bodytext)
sb.Append(“

“)
sb.Append(FooterText)
sb.Append(“

“)
sb.Append(“”)

Return sb.ToString
End Function
======================================================================
Private Function GetToList(ByVal Strid As String) As String
Dim _sqlConnection As New SqlConnection()
Dim cmdSelect As New SqlCommand()
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim strTo As String = “”
Dim strConn As String = ConfigurationManager.ConnectionStrings(“sqlConnectionString”).ToString()

Try
_sqlConnection.ConnectionString = strConn
_sqlConnection.Open()

cmdSelect.Connection = _sqlConnection
cmdSelect.CommandType = CommandType.Text

cmdSelect.CommandText = “Select Name=MemEmail from Member1 where id= ‘” & Strid & “‘”

da = New SqlDataAdapter(cmdSelect)
da.Fill(ds, “Tasks”)

For Each row As DataRow In ds.Tables(“Tasks”).Rows
strTo = strTo & row(“Name”).ToString
strTo = strTo & “,”
Next
Return strTo
Catch ex As Exception
Return strTo
Finally
strConn = Nothing
da = Nothing
ds = Nothing
cmdSelect = Nothing
End Try
End Function
==========================================================================
Imports Microsoft.VisualBasic
Imports System.Configuration
Imports System.Net.Mail
Imports System
Public Function SendMail() As Boolean

’sends Mail

Dim strPath As String = “”
Dim NewMessage As MailMessage = New MailMessage()
Dim Client As SmtpClient = New SmtpClient()

Try

‘getting body for mail
Dim strbody As String = Body

Arrtoid = Split(ToId, “,”)
Arrccid = Split(CCId, “,”)

If Trim(FromId) “” Then NewMessage.From = New MailAddress(FromId)

For Each strT In Arrtoid
If Trim(strT) “” Then NewMessage.To.Add(New MailAddress(strT))
Next
For Each strC In Arrccid
If Trim(strC) “” Then NewMessage.CC.Add(New MailAddress(strC))
Next

NewMessage.Subject = Subject
NewMessage.Body = strbody

If Trim(AttachmentPath) “” Then
Dim attachFile As Attachment = New Attachment(AttachmentPath)
NewMessage.Attachments.Add(attachFile)
End If

NewMessage.IsBodyHtml = True
Client.Send(NewMessage)
Return True

Catch ex As Exception
Throw ex
Finally
NewMessage = Nothing
Client = Nothing
End Try

End Function

=========================================================================

July 18, 2008 - Posted by kuzhikkattil | Uncategorized | | No Comments Yet

No comments yet.

Leave a comment