unit uROIndyEmail; {----------------------------------------------------------------------------} { RemObjects SDK Library - Indy Components } { } { compiler: Delphi 5 and up, Kylix 2 and up } { platform: Win32, Linux } { } { (c)opyright RemObjects Software. all rights reserved. } { } { Using this code requires a valid license of the RemObjects SDK } { which can be obtained at http://www.remobjects.com. } {----------------------------------------------------------------------------} {$I RemObjects.inc} interface uses Classes, IdSMTP; procedure SendMessage(aSmtpClient:TIdSmtp; aMessage:TStream; const aType,aMessageID:string; const aFrom,aTo:string); const MESSAGE_FILE_EXTENSION = '.dat'; implementation uses {$IFDEF RemObjects_INDY10} IdAttachmentFile, {$ENDIF} SysUtils, IdMessage, uROClasses; procedure SendMessage(aSmtpClient:TIdSmtp; aMessage:TStream; const aType,aMessageID:string; const aFrom,aTo:string); var lMessage:TIdMessage; lTempFile:string; begin lMessage := TIdMessage.Create(nil); try lMessage.From.Address := aFrom; lMessage.Recipients.Add.Address := aTo; lMessage.Subject := aType+' '+aMessageID; lMessage.Body.Text := 'RemObjects SDK Email Channel. http://www.remobjects.com'; lMessage.Headers.Add('X-Mailer: RemObjects SDK Email Channel'); { This is SO lame. unfortunately Indy doesnt allow to send a stream without major work & rewriting stuff. which we _will_ do later. } lTempFile := GetTempPath+aMessageID+MESSAGE_FILE_EXTENSION; try with TFileStream.Create(lTempFile,fmCreate) do try aMessage.Seek(0,soFromBeginning); CopyFrom(aMessage,aMessage.Size); finally Free(); end; {$IFDEF RemObjects_INDY10} TIdAttachmentFile.Create(lMessage.MessageParts, lTempFile); {$ELSE} TIdAttachment.Create(lMessage.MessageParts, lTempFile); {$ENDIF} aSmtpClient.Connect(); try aSmtpClient.Send(lMessage); finally aSmtpClient.Disconnect(); end; finally DeleteFile(lTempFile); end; finally lMessage.Free(); end; end; end.