gpt4 book ai didi

Delphi:将 IMAP 连接到 gmail 帐户

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:36 24 4
gpt4 key购买 nike

我尝试将我连接到一个测试 Gmail 帐户。我已经激活了 IMAP,停止了我的本地防火墙和防病毒软件。

我正在使用 2 个 Indy 组件:

imap: TIdIMAP4; ssl: TIdSSLIOHandlerSocketOpenSSL;

我也是

imap.Connect();

它连接但不久后断开连接。

这里是项目(Delphi XE3),包含用户和密码到 gmail 测试帐户。

http://sqlmis.com/update/testimap.zip

我在 TIdSSLIOHandlerSocketOpenSSL 组件和 TIdIMAP4 中尝试了不同的选项,但没有成功。

凭据是:

host=imap.gmail.com
user=testeustachioi@gmail.com

2 个独立组件是:

object ssl: TIdSSLIOHandlerSocketOpenSSL
OnStatus = sslStatus
Destination = 'imap.gmail.com:993'
Host = 'imap.gmail.com'
MaxLineAction = maException
Port = 993
DefaultPort = 0
SSLOptions.Method = sslvSSLv23
SSLOptions.SSLVersions = [sslvSSLv3, sslvTLSv1]
SSLOptions.Mode = sslmUnassigned
SSLOptions.VerifyMode = []
SSLOptions.VerifyDepth = 0

object imap: TIdIMAP4
OnStatus = imapStatus
IOHandler = ssl
OnDisconnected = imapDisconnected
OnConnected = imapConnected
Password = 'fudbafqpmjgikxct'
Port = 993
Username = 'testeustachioi@gmail.com'
Host = 'imap.gmail.com'
UseTLS = utUseImplicitTLS
SASLMechanisms = <>
MilliSecsToWaitToClearBuffer = 10

非常感谢任何帮助或建议

彼得

P.S.: 这里是imap和ssl组件的日志

SSL Status = Resolving hostname imap.gmail.com.
SSL Status = Connecting to 64.233.167.108.
SSL Info = SSL status: "before/connect initialization"
SSL Info = SSL status: "before/connect initialization"
SSL Info = SSL status: "SSLv2/v3 write client hello A"
SSL Info = SSL status: "SSLv3 read server hello A"
SSL Info = SSL status: "SSLv3 read server certificate A"
SSL Info = SSL status: "SSLv3 read server key exchange A"
SSL Info = SSL status: "SSLv3 read server done A"
SSL Info = SSL status: "SSLv3 write client key exchange A"
SSL Info = SSL status: "SSLv3 write change cipher spec A"
SSL Info = SSL status: "SSLv3 write finished A"
SSL Info = SSL status: "SSLv3 flush data"
SSL Info = SSL status: "SSLv3 read server session ticket A"
SSL Info = SSL status: "SSLv3 read finished A"
SSL Info = SSL status: "SSL negotiation finished successfully"
SSL Info = SSL status: "SSL negotiation finished successfully"
SSL Info = Cipher: name = ECDHE-RSA-RC4-SHA; description = ECDHE-RSA-RC4-SHA SSLv3 Kx=ECDH Au=RSA Enc=RC4(128) Mac=SHA1
; bits = 128; version = TLSv1/SSLv3;
Status = Connected.
IMAP Connected SUCCESS
Status = Disconnecting.
IMAP DISCONNECTED
Status = Disconnected.

这里是完整的单元代码:

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdComponent, IdIOHandler,

IdException,

IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdIMAP4, IdMessage,
IdBaseComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,
IdMessageClient, Vcl.StdCtrls;

type
TForm1 = class(TForm)
mess: TIdMessage;
imap: TIdIMAP4;
ssl: TIdSSLIOHandlerSocketOpenSSL;
mLog: TMemo;
Button1: TButton;
lbFolder: TListBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure imapConnected(Sender: TObject);
procedure imapDisconnected(Sender: TObject);
procedure imapStatus(ASender: TObject; const AStatus: TIdStatus;
const AStatusText: string);
procedure sslStatus(ASender: TObject; const AStatus: TIdStatus;
const AStatusText: string);
procedure sslStatusInfo(const AMsg: string);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
sender_mail, sender_name, uid : string;
begin
imap.Connect();
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
imap.ListMailBoxes(lbFolder.Items);
end;

procedure TForm1.imapConnected(Sender: TObject);
begin
mLog.Lines.Add('IMAP Connected SUCCESS');
end;

procedure TForm1.imapDisconnected(Sender: TObject);
begin
mLog.Lines.Add('IMAP DISCONNECTED');
end;

procedure TForm1.imapStatus(ASender: TObject; const AStatus: TIdStatus;
const AStatusText: string);
begin
mLog.Lines.Add('Status = ' + AStatusText);
end;

procedure TForm1.sslStatus(ASender: TObject; const AStatus: TIdStatus;
const AStatusText: string);
begin
mLog.Lines.Add('SSL Status = ' + AStatusText);
end;

procedure TForm1.sslStatusInfo(const AMsg: string);
begin
mLog.Lines.Add('SSL Info = ' + AMsg);
end;

end.

最佳答案

我为这个 imap 连接花了很多时间,尝试了其他组件,最后,..再次重新检查,连接凭据错误(一个字符错误)。现在它起作用了。很抱歉打扰彼得

关于Delphi:将 IMAP 连接到 gmail 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28411182/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com