Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to read gmail emails by using imap
I got those code from searching
C#
using (Imap imap = new Imap())
{
    imap.Connect("imap.gmail.com");   // or ConnectSSL 
    imap.UseBestLogin("********@gmail.com", "*******");
    imap.SelectInbox();
    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)
        {
            MessageBox.Show(attachment.SafeFileName);
        }
        break;
    }
    imap.Close();
}

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

I don't understand I must connect to what?
Posted
Updated 28-Aug-17 4:54am
v2
Comments
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("imap.gmail.com", 993);
rather than
imap.Connect("imap.gmail.com");
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)...
https://support.google.com/mail/troubleshooter/1668960?hl=en#ts=1665018%2C1665144

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