Unable to connect to gmail/Outlook using IMAP in python












0















I have tried to connect to the Gmail server using IMAP in Spyder(Python 3.6) using the Chilkat package.
I have enabled the IMAP for all Mail in the Settings>Forwarding and POP/IMAP and then I have also enabled the less secure apps tab here https://myaccount.google.com/lesssecureapps?pli=1 after signing in. But in this code



import sys
import chilkat

imap = chilkat.CkImap()

# Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("Anything for 30-day trial")
if (success != True):
print(imap.lastErrorText())
sys.exit()

# Connect to an IMAP server.
# Use TLS
imap.put_Ssl(True)
imap.put_Port(993)
success = imap.Connect("imap.gmail.com")


The success variable which is a boolean remains False. Please help me. My aim is to fetch all attachments from Outlook Server and dump them into a file.But I cannot even connect to the Gmail server. I tried to use "imap.mail.Outlook.com" but that also failed. I do not know the steps to enable IMAP in Outlook. But even if it is enabled in Gmail, why is it not working?










share|improve this question























  • I think This problem arose because the connection with the imap server could not occur despite the changes you made.

    – Saradamani
    Nov 20 '18 at 10:21











  • Have you verified using telnet or socat or the like that your host can reach imap.gmail.com's IMAP port? It is blocked by default on a lot of firewalls.

    – Max
    Nov 20 '18 at 15:27
















0















I have tried to connect to the Gmail server using IMAP in Spyder(Python 3.6) using the Chilkat package.
I have enabled the IMAP for all Mail in the Settings>Forwarding and POP/IMAP and then I have also enabled the less secure apps tab here https://myaccount.google.com/lesssecureapps?pli=1 after signing in. But in this code



import sys
import chilkat

imap = chilkat.CkImap()

# Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("Anything for 30-day trial")
if (success != True):
print(imap.lastErrorText())
sys.exit()

# Connect to an IMAP server.
# Use TLS
imap.put_Ssl(True)
imap.put_Port(993)
success = imap.Connect("imap.gmail.com")


The success variable which is a boolean remains False. Please help me. My aim is to fetch all attachments from Outlook Server and dump them into a file.But I cannot even connect to the Gmail server. I tried to use "imap.mail.Outlook.com" but that also failed. I do not know the steps to enable IMAP in Outlook. But even if it is enabled in Gmail, why is it not working?










share|improve this question























  • I think This problem arose because the connection with the imap server could not occur despite the changes you made.

    – Saradamani
    Nov 20 '18 at 10:21











  • Have you verified using telnet or socat or the like that your host can reach imap.gmail.com's IMAP port? It is blocked by default on a lot of firewalls.

    – Max
    Nov 20 '18 at 15:27














0












0








0








I have tried to connect to the Gmail server using IMAP in Spyder(Python 3.6) using the Chilkat package.
I have enabled the IMAP for all Mail in the Settings>Forwarding and POP/IMAP and then I have also enabled the less secure apps tab here https://myaccount.google.com/lesssecureapps?pli=1 after signing in. But in this code



import sys
import chilkat

imap = chilkat.CkImap()

# Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("Anything for 30-day trial")
if (success != True):
print(imap.lastErrorText())
sys.exit()

# Connect to an IMAP server.
# Use TLS
imap.put_Ssl(True)
imap.put_Port(993)
success = imap.Connect("imap.gmail.com")


The success variable which is a boolean remains False. Please help me. My aim is to fetch all attachments from Outlook Server and dump them into a file.But I cannot even connect to the Gmail server. I tried to use "imap.mail.Outlook.com" but that also failed. I do not know the steps to enable IMAP in Outlook. But even if it is enabled in Gmail, why is it not working?










share|improve this question














I have tried to connect to the Gmail server using IMAP in Spyder(Python 3.6) using the Chilkat package.
I have enabled the IMAP for all Mail in the Settings>Forwarding and POP/IMAP and then I have also enabled the less secure apps tab here https://myaccount.google.com/lesssecureapps?pli=1 after signing in. But in this code



import sys
import chilkat

imap = chilkat.CkImap()

# Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("Anything for 30-day trial")
if (success != True):
print(imap.lastErrorText())
sys.exit()

# Connect to an IMAP server.
# Use TLS
imap.put_Ssl(True)
imap.put_Port(993)
success = imap.Connect("imap.gmail.com")


The success variable which is a boolean remains False. Please help me. My aim is to fetch all attachments from Outlook Server and dump them into a file.But I cannot even connect to the Gmail server. I tried to use "imap.mail.Outlook.com" but that also failed. I do not know the steps to enable IMAP in Outlook. But even if it is enabled in Gmail, why is it not working?







python imap chilkat-email






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 9:28









Sounak BanerjeeSounak Banerjee

265




265













  • I think This problem arose because the connection with the imap server could not occur despite the changes you made.

    – Saradamani
    Nov 20 '18 at 10:21











  • Have you verified using telnet or socat or the like that your host can reach imap.gmail.com's IMAP port? It is blocked by default on a lot of firewalls.

    – Max
    Nov 20 '18 at 15:27



















  • I think This problem arose because the connection with the imap server could not occur despite the changes you made.

    – Saradamani
    Nov 20 '18 at 10:21











  • Have you verified using telnet or socat or the like that your host can reach imap.gmail.com's IMAP port? It is blocked by default on a lot of firewalls.

    – Max
    Nov 20 '18 at 15:27

















I think This problem arose because the connection with the imap server could not occur despite the changes you made.

– Saradamani
Nov 20 '18 at 10:21





I think This problem arose because the connection with the imap server could not occur despite the changes you made.

– Saradamani
Nov 20 '18 at 10:21













Have you verified using telnet or socat or the like that your host can reach imap.gmail.com's IMAP port? It is blocked by default on a lot of firewalls.

– Max
Nov 20 '18 at 15:27





Have you verified using telnet or socat or the like that your host can reach imap.gmail.com's IMAP port? It is blocked by default on a lot of firewalls.

– Max
Nov 20 '18 at 15:27












1 Answer
1






active

oldest

votes


















0














The 1st step is to examine the contents of the imap.LastErrorText property to see what happened. For example:



#  Connect to an IMAP server.
# Use TLS
imap.put_Ssl(True)
imap.put_Port(993)
success = imap.Connect("imap.someMailServer.com")
if (success != True):
print(imap.lastErrorText())
sys.exit()


My guess is that a firewall (software or hardware) is blocking the outbound connection.



An alternative solution is to use the GMail REST API as shown in these examples: https://www.example-code.com/python/gmail.asp The HTTP ports (443) are unlikely to be blocked by a firewall. You would download into a Chilkat Email object and then save attachments in exactly the same way had you downloaded via IMAP.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389899%2funable-to-connect-to-gmail-outlook-using-imap-in-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The 1st step is to examine the contents of the imap.LastErrorText property to see what happened. For example:



    #  Connect to an IMAP server.
    # Use TLS
    imap.put_Ssl(True)
    imap.put_Port(993)
    success = imap.Connect("imap.someMailServer.com")
    if (success != True):
    print(imap.lastErrorText())
    sys.exit()


    My guess is that a firewall (software or hardware) is blocking the outbound connection.



    An alternative solution is to use the GMail REST API as shown in these examples: https://www.example-code.com/python/gmail.asp The HTTP ports (443) are unlikely to be blocked by a firewall. You would download into a Chilkat Email object and then save attachments in exactly the same way had you downloaded via IMAP.






    share|improve this answer




























      0














      The 1st step is to examine the contents of the imap.LastErrorText property to see what happened. For example:



      #  Connect to an IMAP server.
      # Use TLS
      imap.put_Ssl(True)
      imap.put_Port(993)
      success = imap.Connect("imap.someMailServer.com")
      if (success != True):
      print(imap.lastErrorText())
      sys.exit()


      My guess is that a firewall (software or hardware) is blocking the outbound connection.



      An alternative solution is to use the GMail REST API as shown in these examples: https://www.example-code.com/python/gmail.asp The HTTP ports (443) are unlikely to be blocked by a firewall. You would download into a Chilkat Email object and then save attachments in exactly the same way had you downloaded via IMAP.






      share|improve this answer


























        0












        0








        0







        The 1st step is to examine the contents of the imap.LastErrorText property to see what happened. For example:



        #  Connect to an IMAP server.
        # Use TLS
        imap.put_Ssl(True)
        imap.put_Port(993)
        success = imap.Connect("imap.someMailServer.com")
        if (success != True):
        print(imap.lastErrorText())
        sys.exit()


        My guess is that a firewall (software or hardware) is blocking the outbound connection.



        An alternative solution is to use the GMail REST API as shown in these examples: https://www.example-code.com/python/gmail.asp The HTTP ports (443) are unlikely to be blocked by a firewall. You would download into a Chilkat Email object and then save attachments in exactly the same way had you downloaded via IMAP.






        share|improve this answer













        The 1st step is to examine the contents of the imap.LastErrorText property to see what happened. For example:



        #  Connect to an IMAP server.
        # Use TLS
        imap.put_Ssl(True)
        imap.put_Port(993)
        success = imap.Connect("imap.someMailServer.com")
        if (success != True):
        print(imap.lastErrorText())
        sys.exit()


        My guess is that a firewall (software or hardware) is blocking the outbound connection.



        An alternative solution is to use the GMail REST API as shown in these examples: https://www.example-code.com/python/gmail.asp The HTTP ports (443) are unlikely to be blocked by a firewall. You would download into a Chilkat Email object and then save attachments in exactly the same way had you downloaded via IMAP.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 20:16









        MattMatt

        20013




        20013






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389899%2funable-to-connect-to-gmail-outlook-using-imap-in-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

            A Topological Invariant for $pi_3(U(n))$