zoukankan      html  css  js  c++  java
  • 关于 邮件收发 的 外文资料,(珍贵~~,没看到比这个更详细的解释了)

    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)

  • 相关阅读:
    0108 创建表约束
    Mybatis 将数据库中查出的记录,一对多返回,即分组,然后返回每个组的所有数据
    SQL主表、从表
    MySQL中添加、删除字段,使用SQL语句操作
    git 将远程工作分支合并到本地dev分支
    MySQL inner join 和 left join 的区别
    Mysql union 和 order by 同时使用需要注意的问题
    The used SELECT statements have a different number of columns
    Every derived table must have its own alias(MySQL报错:每个派生表都必须有自己的别名)
    MySQL 日期格式化及字符串、date、毫秒互相转化
  • 原文地址:https://www.cnblogs.com/linyawen/p/2183737.html
Copyright © 2011-2022 走看看