use indy SMTP to send Gmail messages in Delphi [Go]
2012-01-01 22:44:30| Category: Delphi | Tags: | Report | Font size Big medium small subscription
e-mail in Delphi is very simple, the way to send SSL Gmail email is also very simple, as long as the use of idsmtp attached to a tidssliohandlersocket on it. Using Controls 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 '; //Set message MailMessage.From.Address: = ' [email Protected] '; MailMessage.Recipients.EMailAddresses: = stomail; Mailmessage.subject: = Ssubject; MailMessage.Body.Text: = scontent; //Send mail try try &NBSP Smtp. Connect (+); SMTP. Send (MailMessage); ShowMessage (' send Success '); except on e:exception do Sho Wmessage (' Send failed: ' + e.message '); end; finally if SMTP. connectedthen SMTP. disconnect; end; mailmessage.free; sslsocket.free; SMTP. Free;end, after compiling, requires the support of SSL dynamic library, which can be downloaded to the Indy website. If you need to send an attachment, you can send it again before you add the following similar code //add attachments to the message tidattachment.create (Mailmessage.messageparts, Sattachmentfilename); ———— –indy required SSL Support DLL http://www.indyproject.org/Sockets/SSL.EN.aspx
Use indy SMTP to send Gmail messages in Delphi [go]