Saturday, September 30, 2006

Footprints

You might have read this beautiful story but I wanted to share it anyway. Here it goes...

One night a man had a dream. He dreamt he was walking along the beach with the Lord. Across the sky flashed scenes from his life. For each scene, he noticed two sets of footprints in the sand: one belonging to him, and the other to the Lord.
    

When the last scene of his life flashed before him, he looked back at the footprints in the sand. He noticed that many times along the path of his life there was only one set of footprints. He also noticed that it happened at the very lowest and saddest times of his life.

This really bothered him, and he questioned the Lord about it. “LORD, you said that once I decided to follow you, you'd walk with me all the way. But I have noticed that during the most troublesome times in my life,there is only one set of footprints. I don't understand why when I needed you most you would leave me."

The Lord replied, “My son, my precious child, I love you and would never leave you. During your times of trial and suffering, when you see only one set of footprints, it was then that I carried you.

Source: Read in a book and later on the web

Friday, September 22, 2006

.NET 2.0 Email

As you know .NET 1.x used System.Web.Mail namespace which was a wrapper around old CDONTS and CDOSYS dlls. Microsoft.Net 2.0 introduces System.Net.Mail Namespace which is written from the ground up without any interop. So, it is not dependent on COM libraries. In most cases you face with situations for sending a simple email with plain text, with attachment or authenticated email. I wrote this example in three simple subroutines. Depends on your need or you can use either one or mix and match. There is more variety or flavors can be added like Cc, bcc, html format with or without images etc. I targeted the common uses.

This namespace is much more versatile than old CDO dependent System.Web.Mail. You can do a lot more in this new namespace. More features were presented in Microsoft Seminar. For detail information you can visit http://www.systemnetmail.com

I have created an Email Component using .NET 2.0, which can be used in your Web based or Windows based application to send email. If you are just sending regular message without any attachment or authentication, then you do not need this component. You can directly use System.Net.Mail namespace and add 2 lines of code.But if you are going to use attachments and perform user authentication dynamically then you can utilize this component.

Example for Basic and Advance use is given below. I created this component before I attended the Microsoft Seminar, so I have not yet implement additional cool features for email Content such as LinkedResource, ContentLink and AlternateView etc. Not sure if everyone needs it.

Basic Email - Just 2 lines of Code (VB.NET)
You can create four text boxes on a web page for From, To, Subject and Body and then replace the hard coded values with corresponding text box text. The following code assumes that you are using the local SMTP service of the machine on which this code is running.

Private Sub SendEmail()
 
    Dim objEMail As New System.Net.Mail.SmtpClient
 
    objEMail.Host = "localhost" ' If you have not defined the host in web.config
 
    objEMail.Send("From_You@YourDomain.com", "To_Friend@Domain.com", "Subject: - Testing .NET 2.0 Email", "Body: - You Got mail from .NET 2.0 NameSpace")
 
End Sub
 

Plain Text 

Public Function SendEmail(ByVal addressFrom As String, ByVal addressTo As String, _
 
                                     ByVal subject As String, ByVal bodyText As String) As Boolean
 
  Try
 
      Dim emailMsg As New System.Net.Mail.MailMessage(addressFrom, addressTo, subject, bodyText)
 
      Dim smtpClient As New System.Net.Mail.SmtpClient()
 
      smtpClient.Send(emailMsg)
 
      Return True
 
  Catch
 
      Return False
 
  End Try
 
End Function
 

Attachment

Public Function SendEmailWithAttachment(ByVal addressFrom As String, ByVal addressTo As String, _
 
                                     ByVal subject As String, ByVal bodyText As String, _
 
                                     ByVal fileNameWithFullPath As String) As Boolean
 
 Try
 
     Dim emailMsg As New System.Net.Mail.MailMessage(addressFrom, addressTo, subject, bodyText)
 
     Dim smtpClient As New System.Net.Mail.SmtpClient()
 
     'Attach file if it exists
 
     If File.Exists(fileNameWithFullPath) Then
 
         If Not emailMsg.Attachments Is Nothing Then
 
             Dim fileAttachment As New Net.Mail.Attachment(fileNameWithFullPath)
 
             emailMsg.Attachments.Add(fileAttachment)
 
         End If
 
     End If
 
     smtpClient.Send(emailMsg)
 
     Return True
 
 Catch
 
     Return False
 
 End Try
 
End Function
 

     

Authenticated

The following function sends an authenticated Email that means it uses email server, port number, user id and password as additional parameters.   You may wish to turnoff the authentication anytime and use the same code.  If you have customers who have use your application to send emails to their respective clients, you will pass their stored email server information dynamically through this function.

 

Public Function SendAuthenticatedEmail(ByVal addressFrom As String, ByVal addressTo As String, _
 
                                         ByVal subject As String, ByVal bodyText As String, _
 
                                         ByVal isAutorizationRequired As Boolean, _
 
                                         ByVal emailServer As String, ByVal emailServerPort As Integer, _
 
                                         ByVal emailUser As String, ByVal emailUserPassword As String) As Boolean
 
     Try
 
         Dim emailMsg As New System.Net.Mail.MailMessage(addressFrom, addressTo, subject, bodyText)
 
         Dim smtpClient As New Net.Mail.SmtpClient
 
         If emailServer IsNot Nothing Then
 
             smtpClient = New Net.Mail.SmtpClient(emailServer, emailServerPort)
 
             If isAutorizationRequired Then
 
                 If emailUser IsNot Nothing And emailUserPassword IsNot Nothing Then
 
                     smtpClient.UseDefaultCredentials = False
 
                     smtpClient.Credentials = New System.Net.NetworkCredential(emailUser, emailUserPassword)
 
                 End If
 
             Else
 
                 smtpClient.Credentials = Net.CredentialCache.DefaultNetworkCredentials()
 
             End If
 
         ElseIf smtpClient.Host Is Nothing Then
 
             smtpClient = New Net.Mail.SmtpClient(Environment.MachineName)
 
             smtpClient.Credentials = Net.CredentialCache.DefaultNetworkCredentials()
 
         End If
 
         smtpClient.Send(emailMsg)
 
         Return True
 
     Catch
 
         Return False
 
     End Try
 
 End Function
 
 

 

Web.Config

 

You can define smtp mail settings under system.net of the web.config file. If you do so, then you do not need to provide the same (as shown above) in your code.

 

 

 

 
 
<system.net>
 
   <mailSettings>
 
       <smtp deliveryMethod="network" from="you@yourdomain.com" >
 
           <network host="mysmtpserver.net" port="25" userName="username" password="password" defaultCredentials="true/false"/>
 
       </smtp>
 
    </mailSettings>
 
</system.net>
 

If you are using default settings of smtp then you do not need to provide port, userName, password and defaultCredentials value. In case of secure authentication, you will need to provide userName, password and set the defaultCredentials value to false.

 

Friday, September 15, 2006

Understanding Yoga

Let's understand Yoga by diving into ancient texts. Tracing Yoga in the Vedas and Tantras. What kind of Yoga they reveal to us and what kind of yoga we practice today?

On a high level, there are two orientation of Yoga, both lead to Samadhi or transcendence.  
  1. Vedic Yoga – based on Vedas
  2. Tantric Yoga – based on Tantras

Krishna in Bhagwat Gita revealed three types of - Karma Yoga, Jnana Yoga, and Bhakti Yoga. Later around 2BC, Patanjali compiled a text - Yoga Sutra. This is also known as Raja Yoga and Classical Yoga. Bhagwat Gita is considered as fifth Veda and a Vedanta text. Thus, there are four main paths of Yoga inspired by the Vedic tradition.

  1. Karma Yoga - Yoga of Action
  2. Jnana Yoga - Yoga of Knowledge
  3. Bhakti Yoga -Yoga of Devotion
  4. Raja Yoga – Yoga of Meditation

Philosophically and technically, the science of classical yoga is one of the six Darshana (philosophical viewpoint), has the foundation in Sankhya Darshana. These Darshana accepted the Vedas as the final authority. They are closely linked. They are more geared towards - knowledge or mind.

On the other hand, Tantric practitioner, especially from Nath sect, realized that it is not easy to sit into meditation. It requires the involvement of body and breath to reach to the higher state of mind. Thus, around 15AD, Swami Svatmarama wrote and complied the practices of Hatha Yoga, in a book called Hatha Yoga Pradipika. This is considered one of the primary text on Hatha Yoga. Hatha Yoga is considered a tool or stair to reach the heights of Raja Yoga.

  • Hatha Yoga – Yoga of Body, Breath/Energy and Mind

Tantra neither accepts or rejects the Vedas, but intertwined and further strengthens the yoga philosophy and practices by providing more practical tools and techniques. Thus, philosophy and practices of Yoga are derived from both Vedic and Tantric systems. Tantric practices are more geared towards energy or power. There are many other kinds of Yoga available in Tantric tradition, such as Kundalini Yoga, Laya Yoga, Nada Yoga, Swara Yoga, etc. Tantra uses everything available to us to speed up the process for transcendence.

Today’s Yoga
Today, most people practice some form of Tantric Hatha Yoga. As per Hatha Yoga Pradipika, Hatha Yoga contains 10 major components, however, most practitioner today mainly focuses on one or two components, e.g. Asana practices and call it Yoga.

Thus, most individuals generally define Yoga as Asana or fitness exercises which are nothing but the first step of Hatha Yoga. Even you are just doing yoga-asana, but the most important thing is that you have to be regular in practice to experience the benefits. It does not matter whatever time you can allocate from your daily life, it can be 30 minutes or an hour or two; you must be as regular as you brush your teeth.

Being a Yoga Student for years, I can say that modern medicine has its own value and place but regular practice of yoga can keep a person healthy at body, mind, and spirit without any negative side effects.