Indy10收发Hotmail邮件

本文介绍如何配置Hotmail的POP3及SMTP服务来实现邮件客户端的收发功能,包括必要的SSL/TLS设置和常见问题解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

hotmail开放了pop3,可以使用客户端工具收取邮件了。

POP 服务器: pop3.live.com (端口 995)
需要 POP SSL?: 是的
用户名: Windows Live ID, 比如:livesino@hotmail.com
密码: 对应 Windows Live ID 的密码
SMTP 服务器: smtp.live.com (端口 25)
需要身份验证?: 是的
需要 TLS/SSL?: 是的

使用indy,需要SSL认证,到网上查阅 ,看到了Marco Cantù的文章:

 

Send mail to GMail using Indy

 

Once you've moved your email accounts to GMail (or even entire domains), you have to fix the code you use in your Delphi programs for generating and sending email automatically. In fact, GMail uses the SMTP protocol for sending email, but with a specific form of SSH encryption called TLS.


 

To make things even more complicated, different clients use different ports and configurations. In particular, Outlook (which providees no TLS support) has different settings. For Indy, you can follow the settings used by other client programs, like those provided for Thunderbird. More info on the various ports in this newsgroup post:

Gmail uses 25, 465 and 587 for SMTP, but since almost all isps block 25, 465 is the preferred SMTP with SSL for gmail, and 587 is the preferred SMTP with TLS port.


 

Here is the code of a demo program, with the DFM file and the actual Delphi code (which is the same you'd generally use):


 

  object IdSMTP1: TIdSMTP
    OnStatus = IdSMTP1Status
    IOHandler = IdSSLIOHandlerSocketOpenSSL1
    Host = 'smtp.gmail.com'
    Password = '***'
    Port = 587
    SASLMechanisms = <>
    UseTLS = utUseExplicitTLS
    Username = '****'
  end
  object IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL
    Destination = 'smtp.gmail.com:587'
    Host = 'smtp.gmail.com'
    MaxLineAction = maException
    Port = 587
    SSLOptions.Method = sslvTLSv1
    SSLOptions.Mode = sslmUnassigned
    SSLOptions.VerifyMode = []
    SSLOptions.VerifyDepth = 0
    OnStatusInfo = IdSSLIOHandlerSocketOpenSSL1StatusInfo
  end
      


 

      IdSMTP1.Connect;
      IdSMTP1.Send(IdMessage1);
      IdSMTP1.Disconnect;
      


 

Where IdMessage1 is the message you want to send. Of course, you can both send messages to your gmail account or to any other account from you GMail account.

Notice: If you don't use "explicit TLS" you'll have to make extra initialization calls (like: IdSMTP1.SendCmd('STARTTLS', 220);). Finally, the IdSSLIOHandlerSocketOpenSSL1StatusInfo event handler produces a report like this:

      SSL status: "before/connect initialization"
      SSL status: "before/connect initialization"
      SSL status: "SSLv3 write client hello A"
      SSL status: "SSLv3 read server hello A"
      SSL status: "SSLv3 read server certificate A"
      SSL status: "SSLv3 read server done A"
      SSL status: "SSLv3 write client key exchange A"
      SSL status: "SSLv3 write change cipher spec A"
      SSL status: "SSLv3 write finished A"
      SSL status: "SSLv3 flush data"
      SSL status: "SSLv3 read finished A"
      SSL status: "SSL negotiation finished successfully"
      status: "SSL negotiation finished successfully"
      Cipher: name = [...]; description = [...] SSLv3 Kx=RSA Au=RSA  Enc=3DES(168)

 

 

我没有测试gmail,连接hotmail,出错,后来反复尝试,将idpop的useTLS属性改为utUseImplicitTLS就顺利通过了。

注意:SSL需要下载DLL支持:

http://www.indyproject.org/Sockets/SSL.EN.aspx

 

注意:如果开着瑞星,可能出现收邮件正常,而发邮件失败的问题,用Foxmail在STARTTLS处就停止了,最后也发送失败,这个问题我折腾了好久,最后才发现是瑞星的问题!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值