Sample code for 30+ languages & platforms
Visual Basic 6.0

Log In to an IMAP Server

See more IMAP Examples

Demonstrates the Chilkat Imap.Login method, which authenticates the connected IMAP session using a login name and password. Connect must be called first. This example connects, logs in, and disconnects.

Background: Authentication is a distinct step from connecting: after the TCP/TLS connection is up, Login sends the credentials so the server will grant access to the account's mailboxes. The exact mechanism (plain LOGIN, SASL, or OAuth2) depends on the server and the AuthMethod setting. For providers that require OAuth2 (such as Gmail and Outlook.com), the password is an access token rather than an account password.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Demonstrates the Imap.Login method, which authenticates the connected IMAP session using
'  a login name and password.  Call Connect first.

Dim imap As New ChilkatImap

imap.Ssl = 1
imap.Port = 993

'  Connect before logging in.
success = imap.Connect("imap.example.com")
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If

'  Authenticate with the login name and password.
success = imap.Login("user@example.com","myPassword")
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If

Debug.Print "Logged in to the IMAP server."

success = imap.Disconnect()
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If