欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

在Delphi中使用indy SMTP发送gmail邮件[转]

发布时间:2023/12/20 编程问答 51 豆豆
生活随笔 收集整理的这篇文章主要介绍了 在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邮件[转]的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。