Click here to Skip to main content
15,942,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to read gmail emails by using imap
I got those code from searching
using (Imap imap = new Imap())
    imap.Connect("");   // or ConnectSSL 
    imap.UseBestLogin("********", "*******");
    List<long> uids = imap.Search(Flag.Unseen);
    List<MessageInfo> infos = imap.GetMessageInfoByUID(uids);
    foreach (MessageInfo info in infos)
        MessageBox.Show("Subject: " + info.Envelope.Subject);
        MessageBox.Show("From: " + info.Envelope.From);
        MessageBox.Show("To: " + info.Envelope.To);
        foreach (MimeStructure attachment in info.BodyStructure.Attachments)

but I've this exception in imap.Connect("");
An attempt was made to access a socket in a way forbidden by its access permissions

I don't understand I must connect to what?
Updated 28-Aug-17 4:54am
Kornfeld Eliyahu Peter 22-Nov-15 4:08am    
Check port 143...It is probably blocked...
Kornfeld Eliyahu Peter 22-Nov-15 4:09am    
You may use netstat (command line) to check if someone holds that port for any purpose...
Heba Kamel 22-Nov-15 4:10am    
I solved it by using
imap.ConnectSSL("", 993);
rather than
Kornfeld Eliyahu Peter 22-Nov-15 4:35am    
That's because 993 is the port for secure connection (with IMAP) and probably Google uses it and not port 143 (unsecured)...

1 solution

The message you see mostly means that you have a blocked port in your way to the server...
The port here is 143 (the default port for not-secured IMAP protocol)...
It is also very possible that you need to use port 993 (the port for secured IMAP protocol) as Google request secured connection...
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900