On the next screen, type imap.gmail.com as your incoming mail server.
For the outgoing mail server, type smtp.gmail.com.
For the Access Point, select a predefined one or leave it at “Always ask”.
On the next screen, give a name like Gmail etc., This completes the basic settings, but you need to specify the port and security settings also.
Click on the Gmail mailbox and select ‘Connection Settings’.
Select incoming email settings:
For the username, enter your full email id as in email@example.com.
Type also the password. Scroll below to select Security (ports) and choose SSL/TLS.
Make sure that the Port is set to ‘user defined’ and 993 and security is selected as SSL/TLS. Now go back and select outgoing email settings: Again type in your email id and password. Then scroll down to change the security and port settings. Select security as StartTLS and port as 587.
Thats it! You are done! Go to your main screen of Messaging application, select Gmail and select “Connect”. You can see all the new mails you received in the last 3 days.
Taken from http://www.jaganath.net/content/technology/howto-configure-gmail-imap-on-nokia-n95/123