admin管理员组文章数量:1208155
I have an application that uses Indy TIdIMAP4
to connect to a mail server, read messages, and download attachments. The app works correctly on Windows 10.
When trying to transfer it to Windows 11 or Windows Server 2016, I get the error:
Command Argument Error. 12
I'm using the latest version of the SSL libraries downloaded from GitHub. With the same version, another application works fine, which only sends emails.
Here's the code:
var
IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
IMAP4: TIdIMAP4;
...
begin
IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(IMAP4);
IdSSLIOHandlerSocketOpenSSL1.Destination := IMAP4.Host + ':' + IntToStr(IMAP4.Port);
IdSSLIOHandlerSocketOpenSSL1.Host := IMAP4.Host;
IdSSLIOHandlerSocketOpenSSL1.Port := IMAP4.Port;
IdSSLIOHandlerSocketOpenSSL1.DefaultPort := IMAP4.Port;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvTLSv1_2;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode := sslmUnassigned;
IMAP4.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
for I := 1 to 10 do
begin
try
IMAP4.Connect;
if IMAP4.Connected then
Break;
except
on E: Exception do
AddLog('Error: ' + IntToStr(I) + '. ' + E.Message, False, True);
end;
end;
end;
If you add SSLHandler.StartSSL
before a Connect
call then the error "Socket Error #10038" will appear.
Can you help me figure out why I can't connect to the mail server?
I tried using different versions of the SSL libraries, calling the SSLHandler.StartSSL
method before joining. Nothing helped.
UPDATE:
Here is a log of the connection attempt that fails:
Stat Connected.
Recv 21.01.2025 10:36:24: * OK The Microsoft Exchange IMAP4 service is ready. [TQBNADAAUAAyADgAMABDAEEAMAAxADAAMwAuAFMAVwBFAFAAMgA4ADAALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]
Sent 21.01.2025 10:36:24: C1 LOGIN
Recv 21.01.2025 10:36:24: C1 BAD Command Argument Error. 12
Sent 21.01.2025 10:36:24: C2 LOGOUT
Recv 21.01.2025 10:36:24: * BYE Microsoft Exchange Server IMAP4 server signing off.
C2 OK LOGOUT completed.
Stat Disconnected.
I have an application that uses Indy TIdIMAP4
to connect to a mail server, read messages, and download attachments. The app works correctly on Windows 10.
When trying to transfer it to Windows 11 or Windows Server 2016, I get the error:
Command Argument Error. 12
I'm using the latest version of the SSL libraries downloaded from GitHub. With the same version, another application works fine, which only sends emails.
Here's the code:
var
IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
IMAP4: TIdIMAP4;
...
begin
IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(IMAP4);
IdSSLIOHandlerSocketOpenSSL1.Destination := IMAP4.Host + ':' + IntToStr(IMAP4.Port);
IdSSLIOHandlerSocketOpenSSL1.Host := IMAP4.Host;
IdSSLIOHandlerSocketOpenSSL1.Port := IMAP4.Port;
IdSSLIOHandlerSocketOpenSSL1.DefaultPort := IMAP4.Port;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvTLSv1_2;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode := sslmUnassigned;
IMAP4.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
for I := 1 to 10 do
begin
try
IMAP4.Connect;
if IMAP4.Connected then
Break;
except
on E: Exception do
AddLog('Error: ' + IntToStr(I) + '. ' + E.Message, False, True);
end;
end;
end;
If you add SSLHandler.StartSSL
before a Connect
call then the error "Socket Error #10038" will appear.
Can you help me figure out why I can't connect to the mail server?
I tried using different versions of the SSL libraries, calling the SSLHandler.StartSSL
method before joining. Nothing helped.
UPDATE:
Here is a log of the connection attempt that fails:
Stat Connected.
Recv 21.01.2025 10:36:24: * OK The Microsoft Exchange IMAP4 service is ready. [TQBNADAAUAAyADgAMABDAEEAMAAxADAAMwAuAFMAVwBFAFAAMgA4ADAALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]
Sent 21.01.2025 10:36:24: C1 LOGIN
Recv 21.01.2025 10:36:24: C1 BAD Command Argument Error. 12
Sent 21.01.2025 10:36:24: C2 LOGOUT
Recv 21.01.2025 10:36:24: * BYE Microsoft Exchange Server IMAP4 server signing off.
C2 OK LOGOUT completed.
Stat Disconnected.
Share
Improve this question
edited Jan 21 at 9:02
Remy Lebeau
596k36 gold badges497 silver badges838 bronze badges
asked Jan 20 at 11:21
HardLinkHardLink
111 silver badge1 bronze badge
3
|
1 Answer
Reset to default 1The server is reporting the error message in reply to a LOGIN
command that is not sending any credentials.
The only way that can happen is if you have IMAP4.AuthType
set to iatUserPass
(the default) but both IMAP4.Username
and IMAP4.Password
are blank. Don't do that!
You need to either:
assign valid credentials before calling
IMAP4.Connect()
.set the
AAutoLogin
parameter ofIMAP4.Connect()
to False (it is True by default). You can callIMAP4.Login()
afterwards if needed (after assigning valid credentials).
本文标签: emailDelphi 11IMAPCommand Argument Error 12 on Windows Server 2016Stack Overflow
版权声明:本文标题:email - Delphi 11, IMAP, Command Argument Error. 12 on Windows Server 2016 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738702572a2107747.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
StartSSL()
AT ALL. Indy will call that internally when needed. What is more important is your configuration. WhatPort
are you connecting to, and what do you haveIMAP4.UseTLS
andIdSSLIOHandlerSocketOpenSSL1.PassThrough
set to? These are what influence when and how SSL is initialized on tbe connection. On a side note: you DO NOT need to set the SSLIOHandler'sDestination
,Host
,Port
, orDefaultPort
properties at all.Connect()
will handle that internally. – Remy Lebeau Commented Jan 20 at 17:53IMAO4.Port=993; IMAP4.Destination=outlook.office365.com:993; IMAP4.UseTLS=utUseImplicitTLS; IdSSLIOHandlerSocketOpenSSL1.PassThrough=True;
(False olso was try - have same result) All this parameters are work on Windows 10 ( – HardLink Commented Jan 21 at 6:38TIdLog...
component to theTIdIMAP4.Intercept
property. – Remy Lebeau Commented Jan 21 at 6:40