Экспертная система Delphi.int.ru

Сообщество программистов
Общение, помощь, обмен опытом

Логин:
Пароль:
Регистрация | Забыли пароль?

Delphi.int.ru Expert

Другие разделы портала

Переход к вопросу:

#   

Статистика за сегодня:  


Лучшие эксперты

Подробнее »



Вопрос # 2 258

/ вопрос открыт /

Здравствуйте, уважаемые эксперты!
Пытаюсь разобраться с примером по IdSMTPServer. Понял принцип как работает. Но не могу понять, как научить его переотправлять почту. Задача такая, создать почтовый сервак для локалки. Он определяет адрес назначения, и предает его в IdPOP3Server, если это локальная почта, а если нет - нужно передать в инет.
Пока своего кода не написал, просто пытаюсь разобраться с примером:

Приложение:
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 108528: Main.pas
  11. {
  12. { Rev 1.0 14/08/2004 12:29:18 ANeillans
  13. { Initial Checkin
  14. }
  15. {
  16. Demo Name: SMTP Server
  17. Created By: Andy Neillans
  18. On: 27/10/2002
  19.  
  20. Notes:
  21. Demonstration of SMTPServer (by use of comments only!!)
  22. Read the RFC to understand how to store and manage server data, and
  23. therefore be able to use this component effectivly.
  24.  
  25. Version History:
  26. 14th Aug 04: Andy Neillans
  27. Updated for Indy 10, rewritten IdSMTPServer
  28. 12th Sept 03: Andy Neillans
  29. Cleanup. Added some basic syntax checking for example.
  30.  
  31. Tested:
  32. Indy 10:
  33. D5: Untested
  34. D6: Untested
  35. D7: Untested
  36. }
  37. unit Main;
  38.  
  39. interface
  40.  
  41. uses
  42. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  43. IdBaseComponent, IdComponent, IdTCPServer, IdSMTPServer, StdCtrls,
  44. IdMessage, IdEMailAddress, IdCmdTCPServer, IdExplicitTLSClientServerBase,
  45. IdCustomTCPServer;
  46.  
  47. type
  48. TForm1 = class(TForm)
  49. Memo1: TMemo;
  50. Label1: TLabel;
  51. Label2: TLabel;
  52. Label3: TLabel;
  53. ToLabel: TLabel;
  54. FromLabel: TLabel;
  55. SubjectLabel: TLabel;
  56. IdSMTPServer1: TIdSMTPServer;
  57. btnServerOn: TButton;
  58. btnServerOff: TButton;
  59. procedure btnServerOnClick(Sender: TObject);
  60. procedure btnServerOffClick(Sender: TObject);
  61. procedure IdSMTPServer1MsgReceive(ASender: TIdSMTPServerContext;
  62. AMsg: TStream; var LAction: TIdDataReply);
  63. procedure IdSMTPServer1RcptTo(ASender: TIdSMTPServerContext;
  64. const AAddress: String; var VAction: TIdRCPToReply;
  65. var VForward: String);
  66. procedure IdSMTPServer1UserLogin(ASender: TIdSMTPServerContext;
  67. const AUsername, APassword: String; var VAuthenticated: Boolean);
  68. procedure IdSMTPServer1MailFrom(ASender: TIdSMTPServerContext;
  69. const AAddress: String; var VAction: TIdMailFromReply);
  70. procedure IdSMTPServer1Received(ASender: TIdSMTPServerContext;
  71. AReceived: String);
  72. private
  73. { Private declarations }
  74. public
  75. { Public declarations }
  76. end;
  77.  
  78. var
  79. Form1: TForm1;
  80.  
  81. implementation
  82.  
  83. {$R *.DFM}
  84.  
  85. procedure TForm1.btnServerOnClick(Sender: TObject);
  86. begin
  87. btnServerOn.Enabled := False;
  88. btnServerOff.Enabled := True;
  89. IdSMTPServer1.active := true;
  90. end;
  91.  
  92. procedure TForm1.btnServerOffClick(Sender: TObject);
  93. begin
  94. btnServerOn.Enabled := True;
  95. btnServerOff.Enabled := False;
  96. IdSMTPServer1.active := false;
  97. end;
  98.  
  99. procedure TForm1.IdSMTPServer1MsgReceive(ASender: TIdSMTPServerContext;
  100. AMsg: TStream; var LAction: TIdDataReply);
  101. var
  102. LMsg : TIdMessage;
  103. LStream : TFileStream;
  104. begin
  105. // When a message is received by the server, this event fires.
  106. // The message data is made available in the AMsg : TStream.
  107. // In this example, we will save it to a temporary file, and the load it using
  108. // IdMessage and parse some header elements.
  109.  
  110. LStream := TFileStream.Create(ExtractFilePath(Application.exename) + 'test.eml', fmCreate);
  111. Try
  112. LStream.CopyFrom(AMsg, 0);
  113. Finally
  114. FreeAndNil(LStream);
  115. End;
  116.  
  117. LMsg := TIdMessage.Create;
  118. Try
  119. LMsg.LoadFromFile(ExtractFilePath(Application.exename) + 'test.eml', False);
  120. ToLabel.Caption := LMsg.Recipients.EMailAddresses;
  121. FromLabel.Caption := LMsg.From.Text;
  122. SubjectLabel.Caption := LMsg.Subject;
  123. Memo1.Lines := LMsg.Body;
  124. Finally
  125. FreeAndNil(LMsg);
  126. End;
  127.  
  128. end;
  129.  
  130. procedure TForm1.IdSMTPServer1RcptTo(ASender: TIdSMTPServerContext;
  131. const AAddress: String; var VAction: TIdRCPToReply;
  132. var VForward: String);
  133. begin
  134. // Here we are testing the RCPT TO lines sent to the server.
  135. // These commands denote where the e-mail should be sent.
  136. // RCPT To address comes in via AAddress. VAction sets the return action to the server.
  137.  
  138. // Here, you would normally do:
  139. // Check if the user has relay rights, if the e-mail address is not local
  140. // If the e-mail domain is local, does the address exist?
  141.  
  142. // The following actions can be returned to the server:
  143. {
  144. rAddressOk, //address is okay
  145. rRelayDenied, //we do not relay for third-parties
  146. rInvalid, //invalid address
  147. rWillForward, //not local - we will forward
  148. rNoForward, //not local - will not forward - please use
  149. rTooManyAddresses, //too many addresses
  150. rDisabledPerm, //disabled permentantly - not accepting E-Mail
  151. rDisabledTemp //disabled temporarily - not accepting E-Mail
  152. }
  153.  
  154. // For now, we will just always allow the rcpt address.
  155. VAction := rAddressOk;
  156. end;
  157.  
  158. procedure TForm1.IdSMTPServer1UserLogin(ASender: TIdSMTPServerContext;
  159. const AUsername, APassword: String; var VAuthenticated: Boolean);
  160. begin
  161. // This event is fired if a user attempts to login to the server
  162. // Normally used to grant relay access to specific users etc.
  163. VAuthenticated := True;
  164. end;
  165.  
  166. procedure TForm1.IdSMTPServer1MailFrom(ASender: TIdSMTPServerContext;
  167. const AAddress: String; var VAction: TIdMailFromReply);
  168. begin
  169. // Here we are testing the MAIL FROM line sent to the server.
  170. // MAIL FROM address comes in via AAddress. VAction sets the return action to the server.
  171.  
  172. // The following actions can be returned to the server:
  173. { mAccept, mReject }
  174.  
  175. // For now, we will just always allow the mail from address.
  176. VAction := mAccept;
  177. end;
  178.  
  179. procedure TForm1.IdSMTPServer1Received(ASender: TIdSMTPServerContext;
  180. AReceived: String);
  181. begin
  182. // This is a new event in the rewrite of IdSMTPServer for Indy 10.
  183. // It lets you control the Received: header that is added to the e-mail.
  184. // If you do not want a Received here to be added, set AReceived := '';
  185. // Formatting 'keys' are available in the received header -- please check
  186. // the IdSMTPServer source for more detail.
  187. end;
  188.  
  189. end.


Nasgool Вопрос ожидает решения (принимаются ответы, доступен мини-форум)

Вопрос задал: Nasgool (статус: 2-ой класс)
Вопрос отправлен: 4 января 2009, 10:22
Состояние вопроса: открыт, ответов: 0.


Мини-форум вопроса

Всего сообщений: 1; последнее сообщение — 4 января 2009, 10:24; участников в обсуждении: 1.
Nasgool

Nasgool (статус: 2-ой класс), 4 января 2009, 10:24 [#1]:

И если есть мануал на русском по IdSMTPServer (только не Глубины Инди), дайте ссылку.

Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.

Версия движка: 2.6+ (26.01.2011)
Текущее время: 22 февраля 2025, 11:59
Выполнено за 0.03 сек.