在Delphi中使用indy SMTP发送gmail邮件[转]
生活随笔
收集整理的這篇文章主要介紹了
在Delphi中使用indy SMTP发送gmail邮件[转]
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在Delphi中使用indy SMTP發送gmail郵件[轉]??
2012-01-01 22:44:30|??分類: Delphi |??標簽: |舉報 |字號大中小?訂閱
在Delphi中發送email很簡單,發送ssl方式的gmail郵件也很簡單,只要在使用的idSMTP上附加一個TIdSSLIOHandlerSocket 就可以了。 使用控件 procedure sendMail(sToMail, sSubject, sContent: String); var SMTP: TIdSMTP; MailMessage: TIdMessage; SSLSocket: TIdSSLIOHandlerSocket; begin SMTP ? ? ? ?:= TIdSMTP.Create(nil); SSLSocket := TIdSSLIOHandlerSocket.Create(nil); MailMessage:= TIdMessage.Create(nil); SMTP.IOHandler := SSLSocket; SMTP.Port ? := 465; SMTP.Host := 'smtp.gmail.com'; SMTP.AuthenticationType ?:= atLogin; smtp.UserName ? ? := 'SunnyYu2000'; smtp.Password ? ? ?:= 'xxxxxx'; // 設置郵件的信息 MailMessage.From.Address := 'SunnyYu2000@gmail.com'; MailMessage.Recipients.EMailAddresses := sToMail; MailMessage.Subject := sSubject; ? MailMessage.Body.Text := sContent; //發送郵件 try try SMTP.Connect(1000); SMTP.Send(MailMessage); ShowMessage('發送成功'); except on E:Exception do ShowMessage('發送失敗: ' + E.Message); end; finally if SMTP.Connectedthen SMTP.Disconnect; end; MailMessage.Free; SSLSocket.Free; SMTP.Free; end; 編譯后需要SSL動態庫支持,支持庫可以到Indy網站上下載到。 如果需要發送附件,可以再發送前添加如下類似代碼 // 添加郵件的附件 TIdAttachment.Create(MailMessage.MessageParts, sAttachmentFileName); ————– Indy需要的SSL支持dll下載地址 http://www.indyproject.org/Sockets/SSL.EN.aspx轉載于:https://www.cnblogs.com/honeynm/p/4196087.html
總結
以上是生活随笔為你收集整理的在Delphi中使用indy SMTP发送gmail邮件[转]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大数据项目实战——基于某招聘网站进行数据
- 下一篇: java车牌号识别EasyPR_Easy