You getting error maybe due to smtp and imap wrong port or maybe ssl not enable your settings must be like this.
IMAP server: imap.gmail.com
Security type: SSL
Port: 993
SMTP server: smtp.gmail.com
Port: 465
Security type: SSL
Data Source: smtpimap.email