MailCore / mailcore2

MailCore 2 provide a simple and asynchronous API to work with e-mail protocols IMAP, POP and SMTP. The API has been redesigned from ground up.
Other
2.58k stars 623 forks source link

[Bug] - Check connection is not printing any output #1995

Open kumarkrish85 opened 4 months ago

kumarkrish85 commented 4 months ago

Summary Hello I am trying to connect my company mail server to fetch mail, but i am trying to make a connection to server using the below code, but nothing it get printed , please guide me. I can connect the same server through python imap library

Platform(s) IOS

Happens on Mail Server Outlook365

Piece of code

let session = MCOIMAPSession()
        session.hostname = ""
        session.username = "AutomationAlerts@xxxx.com"
        session.password = "Welcome2024#"
        session.port = 993
        session.allowsFolderConcurrentAccessEnabled = true
        session.connectionType              = MCOConnectionType.TLS
        session.authType                    = MCOAuthType.saslLogin
        session.isCheckCertificateEnabled   = false
        session.isVoIPEnabled               = false
        session.maximumConnections          = 2
        session.timeout                     = 10

        if let loginOperation = session.checkAccountOperation() {
            loginOperation.start { (error) -> Void in
                if (error != nil) {
                    print("Error login:\n\(String(describing: error))")
                } else {
                    print("imapConnect - Successful IMAP connection")
                }
            }
        }

Actual outcome It didn't print anything

Connection Logs

Kindly let me know how to generate connection logs

Expected outcome Mailcore should connect my mail server successfully

Be-Maps commented 4 months ago

One of the 2 below usually works, I am not sure if you deleted or you did not give hostname in code above (i.e. imap.*****.com). Also check the ports, which are used for IMAP TLS or SSL.

if (config.getIMAPSSL().equals("SSL")){
                        session.hostname = config.getIMAPServer()
                        session.username = config.getUserName()
                        session.password = config.getPassword()
                        session.port = UInt32.parseUInt32(config.getIMAPport())
                        session.allowsFolderConcurrentAccessEnabled = true
                        session.connectionType              = MCOConnectionType.TLS
                        session.authType                    = MCOAuthType.saslLogin
                        session.isCheckCertificateEnabled   = false
                        session.isVoIPEnabled               = false
                        session.maximumConnections          = 2
                        session.timeout                     = App.connectionTimeout
                    } else {
                        session.hostname = config.getIMAPServer()
                        session.username = config.getUserName()
                        session.password = config.getPassword()
                        session.port = UInt32.parseUInt32(config.getIMAPport())
                        session.allowsFolderConcurrentAccessEnabled = true
                        session.connectionType              = MCOConnectionType.startTLS
                        session.authType                    = MCOAuthType.saslPlain
                        session.isCheckCertificateEnabled   = false
                        session.isVoIPEnabled               = false
                        session.maximumConnections          = 2
                        session.timeout                     = App.connectionTimeout
                    }

    if let loginOperation = session.checkAccountOperation() {
        do { try await loginOperation.start(); print("imapConnect - Successful IMAP connection") }
        catch { print("imapConnect - IMAP Connect Error: \(error)"); return }
    }
kumarkrish85 commented 4 months ago

@Be-Maps Thanks for the reply. I didn't give the hostname in the query for masking. I will try your suggestion and get back