OAuth 2.0 authentication

Visual Basic Code | ASP Code

This sample connects to POP3 server using OAuth 2.0 access token (which you need to obtain from a mail service provider using their API), logs in e-mail account, and selects "Inbox" folder.

MailBee Objects ships with VBScript OAuth 2.0 samples for Gmail and Office 365. You can find it in My Documents/MailBee Objects/Samples/OAuth2_VBScript folder.

Note that the mail service provider's APIs for obtaining access tokens can be different for web and Windows applications.

[Visual Basic]:

Dim objPOP3

' Create POP3 object
Set objPOP3 = CreateObject("MailBee.POP3")

' Unlock POP3 object
objPOP3.LicenseKey = "put your license key here"

' Set POP3 server name
objPOP3.ServerName = "mail.server.com"

' Set user credentials
objPOP3.UserName = "username" ' Usually, email address
objPOP3.Password = "access_token" ' You get it from the mail service provider using their proprietary API

' OAuth 2.0
objPOP3.AuthMethod = 6

' Connect to the server and log in the mailbox
If objPOP3.Connect Then

  ' Display the number of messages
  MsgBox objPOP3.MessageCount & " messages"

  ' Close the connection
  objPOP3.Disconnect
Else
  ' Display error information
  MsgBox "Error #" & objPOP3.ErrCode
  MsgBox "Server response: " & objPOP3.ServerResponse
End If

[ASP]:

<%
Dim objPOP3

' Create POP3 object
Set objPOP3 = Server.CreateObject("MailBee.POP3")

' Unlock POP3 object
objPOP3.LicenseKey = "put your license key here"

' Set POP3 server name
objPOP3.ServerName = "mail.server.com"

' Set user credentials
objPOP3.UserName = "username" ' Usually, email address
objPOP3.Password = "access_token" ' You get it from the mail service provider using their proprietary API

' OAuth 2.0
objPOP3.AuthMethod = 6

' Connect to the server and log in the mailbox
If objPOP3.Connect Then

  ' Display the number of messages
  Response.Write objPOP3.MessageCount & " messages"

  ' Close the connection
  objPOP3.Disconnect
Else
  ' Display error information
  Response.Write "Error #" & objPOP3.ErrCode & "<br>"
  Response.Write "Server response: " & objPOP3.ServerResponse
End If
%>
See Also:
AuthMethod Property

 


Send feedback to AfterLogic
Copyright © 2002-2022, AfterLogic Corporation. All rights reserved.