To send an email via telnet for testing:
telnet SMTP Server Name 25
EHLO mydomain.tld
MAIL FROM: my@from.address
RCPT TO: my@to.address
DATA
Here you can type the body of the message.
.

To the same thing, but with From: To: and Subject: headers:
telnet SMTP Server Name 25
EHLO mydomain.tld
MAIL FROM: my@from.address
RCPT TO: my@to.address
DATA
From: my@from.address
To: my@to.address
Subject: Here is a subject.

Here you can type the body of the message.
.

Here is how you can do a basic test of an IMAP server via telnet:

telnet IMAP Server Name 143
? LOGIN username password
? LIST “” “*”
? LOGOUT

This will log you in and list the accounts mail folders. Note: This is testing a basic unencrypted login to an IMAP server. Not the way you would want to implement in production, unless implement via localhost.

If you want to test your SSL configuration use openssl instead of telnet:
openssl s_client -connect hostname:portnumber

For example:
openssl s_client -connect SMTP Server Name:465