POP3: Require an STLS Upgrade Before Authentication
Connect to a provider that supports POP STLS on port 110, require the TLS upgrade, then authenticate and obtain a message count. Set PopSsl=false, Pop3Stls=true, and enable certificate verification. Replace the generic host and credentials with settings issued by that provider. Use the provider's OAuth or app-password policy where applicable.
The former example was mislabeled: it connected to Gmail on port 995 using implicit TLS and never performed STLS. Gmail's documented POP configuration remains pop.gmail.com:995 with PopSsl=true; use Gmail POP OAuth2 for that connection.
The required STLS setting fails if the upgrade is unavailable. An opportunistic setting can leave a connection unencrypted and is not used here.
See the Gmail SMTP, IMAP, and POP3 guide for current authentication choices and Gmail-specific examples.
Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @success int
SELECT @success = 0
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
DECLARE @mailman int
EXEC @hr = sp_OACreate 'Chilkat.MailMan', @mailman OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Use a provider that explicitly supports POP STLS on port 110.
-- Gmail documents implicit TLS on pop.gmail.com:995 instead.
EXEC sp_OASetProperty @mailman, 'MailHost', 'pop.example.com'
EXEC sp_OASetProperty @mailman, 'MailPort', 110
EXEC sp_OASetProperty @mailman, 'PopSsl', 0
EXEC sp_OASetProperty @mailman, 'Pop3Stls', 1
EXEC sp_OASetProperty @mailman, 'Pop3StlsIfPossible', 0
EXEC sp_OASetProperty @mailman, 'RequireSslCertVerify', 1
EXEC sp_OASetProperty @mailman, 'PopUsername', 'user@example.com'
EXEC sp_OASetProperty @mailman, 'PopPassword', 'YOUR_PROVIDER_ISSUED_PASSWORD'
EXEC sp_OAMethod @mailman, 'Pop3BeginSession', @success OUT
IF @success <> 1
BEGIN
EXEC sp_OAMethod @mailman, 'Pop3EndSessionNoQuit', @success OUT
PRINT 'POP connection or authentication failed. STLS must succeed before credentials are sent.'
EXEC @hr = sp_OADestroy @mailman
RETURN
END
DECLARE @count int
EXEC sp_OAMethod @mailman, 'CheckMail', @count OUT
IF @count < 0
BEGIN
EXEC sp_OAMethod @mailman, 'Pop3EndSessionNoQuit', @success OUT
PRINT 'Could not obtain the POP message count.'
EXEC @hr = sp_OADestroy @mailman
RETURN
END
PRINT 'Available POP messages: ' + @count
EXEC sp_OAMethod @mailman, 'Pop3EndSession', @success OUT
IF @success <> 1
BEGIN
PRINT 'The count was obtained, but closing the POP session failed.'
END
EXEC @hr = sp_OADestroy @mailman
END
GO