Here are a few steps easy to follow:
1. Login to the GMail account
After logging in to GMail, click on Settings on the upper-right corner, and then click on the Forwarding and POP/IMAP tab. Tick the Enable IMAP option in the IMAP Access section, and then click the Save Changes button.
2. Fire up KMail
Press Alt+F2 and type kmail in the run box that appears. KMail should start, so if a first-run wizard appears, just close it.
3. Configure KMail to use IMAP settings for your GMail account
In KMail, go to Settings->Configure KMail... and click on the Accounts tab.
In the Receiving tab, click the Add... button on the right and then tick the IMAP option in the pop-up window that appears. Next click OK:
Now, a window with IMAP details should appear. Enter the following data:
Account name: you can leave this to the default value, IMAP Account
Incoming mail server: imap.gmail.com
Port: leave this to the default port 143
Login: your GMail account (e.g. email@example.com)
Password: your email (GMail) password
Do not close this window for now. Go to the Security tab and select the Use SSL for secure mail download radio button. This will use encryption for transferring your emails. Click OK, then Apply in the main configuration window.
This should be all. This part takes care about incoming emails via your GMail account.
For outgoing email, go again to Settings->Configure KMail... and then click on the Sending tab. Next, click Add..., check the SMTP account type in the window that appears, give it a name and click the Create and Configure button. Fill in the Outgoing mail server field with smtp.gmail.com and then click OK:
Your GMail account is now synchronized and you can now access it directly in KMail