使用Delphi收发GMail的邮件

时间:2022-03-13 01:19:47
GMAIL的端口和连接方式比较特殊:
SMTP端口为:456
POP3端口为:995
都采用安全连接(SSL)
这些通过Indy组件就可以实现
参考代码如下:
object IdConnectionInterceptOpenSSL1: TIdConnectionInterceptOpenSSL
  SSLOptions.Method = sslvSSLv2
  SSLOptions.Mode = sslmUnassigned
  SSLOptions.VerifyMode = []
  SSLOptions.VerifyDepth = 0
  Left = 56
  Top = 11
end
object IdPOP31: TIdPOP3
  Intercept = IdConnectionInterceptOpenSSL1
  InterceptEnabled = True
  RecvBufferSize = 1024
  OnConnected = IdPOP31Connected
  Left = 26
  Top = 11
end
procedure TForm1.Button1Click(Sender: TObject);
begin
  if IdPOP31.Connected then
    IdPOP31.Disconnect;
  IdPOP31.Host := 'pop.gmail.com';
  IdPOP31.Port := 995;
  IdPOP31.UserID := 'youname@gmail.com';
  IdPOP31.Password := '*********';
  IdPOP31.Connect;
end;
procedure TForm1.IdPOP31Connected(Sender: TObject);
begin
  ShowMessage('连接成功');
end;
举一反三,我想SMTP就没有必要也贴上,搂主自己完善
特别注意:
// 转贴注明作者Zswang wjhu111#21cn.com 2006-12-22
SSL需要如下两个动态连接库
ssleay32.dll
libeay32.dll
Foxmail目录里就有,复制到程序的当前目录即可
否则就叫牛魔王一起来看错误对话框