Gmail IMAP: Connect with an App Password
Authenticate to Gmail over implicit TLS on port 993, then open INBOX read-only and report its message count. No message is downloaded or changed. This replaces ordinary-password login and removes authentication-session logging.
Personal Gmail IMAP is always enabled. Workspace administrators can restrict IMAP access. For OAuth2, use Gmail IMAP token authentication.
Use an account-specific app password generated after enabling 2-Step Verification, loaded from protected configuration. A normal Google password will not work. App passwords may be unavailable under account or Workspace policy; OAuth2 is preferred. Changing the Google account password revokes app passwords. The obsolete less-secure-apps switch is not a setup option. Google app-password requirements.
See the Gmail SMTP, IMAP, and POP3 guide for current authentication choices and Gmail-specific examples.
Chilkat AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
Local $sMailbox = "user@example.com"
$oImap = ObjCreate("Chilkat.Imap")
$oImap.Ssl = True
$oImap.Port = 993
$oImap.RequireSslCertVerify = True
$bSuccess = $oImap.Connect("imap.gmail.com")
If ($bSuccess <> True) Then
ConsoleWrite("Could not establish the Gmail IMAP TLS connection." & @CRLF)
Exit
EndIf
$bSuccess = $oImap.Login($sMailbox,"YOUR_16_CHARACTER_APP_PASSWORD")
If ($bSuccess <> True) Then
$oImap.Disconnect()
ConsoleWrite("IMAP authentication failed. Check the app password, mailbox, and account policy." & @CRLF)
Exit
EndIf
; EXAMINE is read-only; no message is downloaded, marked read, moved, or deleted.
$bSuccess = $oImap.ExamineMailbox("INBOX")
If ($bSuccess <> True) Then
$oImap.Logout()
$oImap.Disconnect()
ConsoleWrite("Could not examine INBOX." & @CRLF)
Exit
EndIf
ConsoleWrite("Messages in INBOX: " & $oImap.NumMessages & @CRLF)
$bSuccess = $oImap.Logout()
$oImap.Disconnect()
If ($bSuccess <> True) Then
ConsoleWrite("The read-only operation completed, but IMAP logout failed." & @CRLF)
EndIf