Tuesday, January 12, 2010

Send an Email via your own host - vb.net

'create instance of MailMessage

Dim mailMessage As New MailMessage()

Try

set smtp authntication for your host- this must have username(full email address. Ex admin@myhost.com) and password which is already registerd in your host

mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1)

mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "admin@myhost.com")

mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "adminpassword")

'set send from email addrss

mailMessage.From = "fromemail@myhost.com"

'recipient's email address

mailMessage.To = "ruwansj@gmail.com"

'email address of the Cc recipient

mailMessage.Cc = ""

'email address of the Bcc recipient

mailMessage.Bcc = ""

'subject of the email message

mailMessage.Subject = "Hello"

'message text format. Can be text or html

mailMessage.BodyFormat = MailFormat.Text

'message body (if you suppose to use html as bodyformat, then you have to use html tags for create mail message.

mailMessage.Body = "Test email for vb.Net ."

'email priority. Can be low, normal or high

mailMessage.Priority = MailPriority.Normal

'mail server used to send this email. modify this line based on your mail server

SmtpMail.SmtpServer = "mail.myhost.com"

'using the static method "Send" of the SmtpMail class to send the mail

SmtpMail.Send(mailMessage)


Catch ex As Exception

Response.Write(ex.Message)

End Try

Saturday, January 9, 2010

Console Application for Read and Compare a letter in text file

Module Module1
'This can use to read list of names in a text file

Sub Main()
Dim txt As String
Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
oRead = oFile.OpenText("C:\sample.txt")


While Not oRead.EndOfStream
'do whatever you want to do
txt = oRead.ReadLine()
Console.WriteLine(txt)

'read text input charactor to be compare

Dim compChar As Char()

compChar = "d"

If compChar = txt.Substring(0, 1) Then
Console.Write("Charactor Found : " & txt)
Console.WriteLine("")
End If

End While

oRead.Close()
Console.ReadKey()

End Sub

End Module




'-------------- Out put ---------------Sample text in sample.txt
Ruwan
daya
Kamal
jagath
Nimal
Rasika
Manoj