在Delphi中使用indy SMTP发送gmail邮件[转]
生活随笔
收集整理的這篇文章主要介紹了
在Delphi中使用indy SMTP发送gmail邮件[转]
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在Delphi中使用indy SMTP發(fā)送gmail郵件[轉(zhuǎn)]??
2012-01-01 22:44:30|??分類: Delphi |??標(biāo)簽: |舉報(bào) |字號(hào)大中小?訂閱
在Delphi中發(fā)送email很簡(jiǎn)單,發(fā)送ssl方式的gmail郵件也很簡(jiǎn)單,只要在使用的idSMTP上附加一個(gè)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'; // 設(shè)置郵件的信息 MailMessage.From.Address := 'SunnyYu2000@gmail.com'; MailMessage.Recipients.EMailAddresses := sToMail; MailMessage.Subject := sSubject; ? MailMessage.Body.Text := sContent; //發(fā)送郵件 try try SMTP.Connect(1000); SMTP.Send(MailMessage); ShowMessage('發(fā)送成功'); except on E:Exception do ShowMessage('發(fā)送失敗: ' + E.Message); end; finally if SMTP.Connectedthen SMTP.Disconnect; end; MailMessage.Free; SSLSocket.Free; SMTP.Free; end; 編譯后需要SSL動(dòng)態(tài)庫(kù)支持,支持庫(kù)可以到Indy網(wǎng)站上下載到。 如果需要發(fā)送附件,可以再發(fā)送前添加如下類似代碼 // 添加郵件的附件 TIdAttachment.Create(MailMessage.MessageParts, sAttachmentFileName); ————– Indy需要的SSL支持dll下載地址 http://www.indyproject.org/Sockets/SSL.EN.aspx轉(zhuǎn)載于:https://www.cnblogs.com/honeynm/p/4196087.html
總結(jié)
以上是生活随笔為你收集整理的在Delphi中使用indy SMTP发送gmail邮件[转]的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 大数据项目实战——基于某招聘网站进行数据
- 下一篇: java车牌号识别EasyPR_Easy