/src/yolk-email-composer.ads

http://github.com/ThomasLocke/yolk · Ada · 152 lines · 76 code · 16 blank · 60 comment · 0 complexity · fd34ab7a9d4059ddbd3e62560473fb89 MD5 · raw file

  1. -------------------------------------------------------------------------------
  2. -- --
  3. -- Copyright (C) 2010-, Thomas ¸cke --
  4. -- --
  5. -- This library is free software; you can redistribute it and/or modify --
  6. -- it under terms of the GNU General Public License as published by the --
  7. -- Free Software Foundation; either version 3, or (at your option) any --
  8. -- later version. This library is distributed in the hope that it will be --
  9. -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
  10. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
  11. -- --
  12. -- As a special exception under Section 7 of GPL version 3, you are --
  13. -- granted additional permissions described in the GCC Runtime Library --
  14. -- Exception, version 3.1, as published by the Free Software Foundation. --
  15. -- --
  16. -- You should have received a copy of the GNU General Public License and --
  17. -- a copy of the GCC Runtime Library Exception along with this program; --
  18. -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
  19. -- <http://www.gnu.org/licenses/>. --
  20. -- --
  21. -------------------------------------------------------------------------------
  22. package Yolk.Email.Composer is
  23. procedure Add_Custom_Header
  24. (ES : in out Structure;
  25. Name : in String;
  26. Value : in String;
  27. Charset : in Character_Set := US_ASCII);
  28. -- Add a custom header to the ES email object. Custom headers are usually
  29. -- things like User-Agent, Organization or X- headers.
  30. procedure Add_File_Attachment
  31. (ES : in out Structure;
  32. Path_To_File : in String;
  33. Charset : in Character_Set := US_ASCII);
  34. -- Add a file attachment to the ES email object. These are _always_ BASE64
  35. -- encoded. At this point we do not check whether the file actually exists,
  36. -- so anything can be added, even an empty String Path_To_File.
  37. procedure Add_From
  38. (ES : in out Structure;
  39. Address : in String;
  40. Name : in String := "";
  41. Charset : in Character_Set := US_ASCII);
  42. -- Add a From mailbox to the email. If multiple From mailboxes are added,
  43. -- then a subsequent call to Set_Sender is required, as per RFC 5322.
  44. procedure Add_Recipient
  45. (ES : in out Structure;
  46. Address : in String;
  47. Name : in String := "";
  48. Kind : in Recipient_Kind := To;
  49. Charset : in Character_Set := US_ASCII);
  50. -- Add a recipient to the email.
  51. procedure Add_Reply_To
  52. (ES : in out Structure;
  53. Address : in String;
  54. Name : in String := "";
  55. Charset : in Character_Set := US_ASCII);
  56. -- Reply-To indicates the address(es) to which the author of the message
  57. -- suggests that replies be sent. In the absence of Reply-To, the default
  58. -- is to send replies to the From mailboxes.
  59. procedure Add_SMTP_Server
  60. (ES : in out Structure;
  61. Host : in String;
  62. Port : in Positive := 25);
  63. -- Set the SMTP servers to use when sending an email. The first server
  64. -- added is the first server tried. If the first server fails, then the
  65. -- system moves on to the next server, until it either runs out of SMTP
  66. -- servers to try, or it manages to send the email.
  67. function Is_Send
  68. (ES : in Structure)
  69. return Boolean;
  70. -- Return True if the email has been successfully delivered to one of the
  71. -- set SMTP servers. False otherwise.
  72. procedure Send
  73. (ES : in out Structure);
  74. -- Process the ES object. This entails composing the email source and
  75. -- sending it via one of the set SMTP servers.
  76. -- Exceptions:
  77. -- Attachment_File_Not_Found
  78. -- No_Address_Set
  79. -- No_Sender_Set_With_Multiple_From
  80. -- No_SMTP_Host_Set
  81. procedure Send
  82. (ES : in out Structure;
  83. From_Address : in String;
  84. From_Name : in String := "";
  85. To_Address : in String;
  86. To_Name : in String := "";
  87. Subject : in String;
  88. Text_Part : in String;
  89. SMTP_Server : in String := "localhost";
  90. SMTP_Port : in Positive := 25;
  91. Charset : in Character_Set := US_ASCII);
  92. -- Convenience wrapper for Send (ES : in out Email_Structure) for Text only
  93. -- emails.
  94. -- Exceptions raised by the "parent" Send procdure are passively propagated
  95. -- up through the call stack to the caller of this Send procedure.
  96. procedure Send
  97. (ES : in out Structure;
  98. From_Address : in String;
  99. From_Name : in String := "";
  100. To_Address : in String;
  101. To_Name : in String := "";
  102. Subject : in String;
  103. Text_Part : in String;
  104. HTML_Part : in String;
  105. SMTP_Server : in String := "localhost";
  106. SMTP_Port : in Positive := 25;
  107. Charset : in Character_Set := US_ASCII);
  108. -- Convenience wrapper for Send (ES : in out Email_Structure) for Text and
  109. -- HTML multipart emails.
  110. -- Exceptions raised by the "parent" Send procdure are passively propagated
  111. -- up through the call stack to the caller of this Send procedure.
  112. procedure Set_HTML_Part
  113. (ES : in out Structure;
  114. Part : in String;
  115. Charset : in Character_Set := US_ASCII);
  116. -- When adding a HTML part to an email, it is automatically converted to
  117. -- a multipart message. If no Text part is added, an empty one will be
  118. -- created automatically.
  119. procedure Set_Sender
  120. (ES : in out Structure;
  121. Address : in String;
  122. Name : in String := "";
  123. Charset : in Character_Set := US_ASCII);
  124. -- If an email has multiple From addresses, then it is required, as per
  125. -- RFC 5322, to set a single Sender.
  126. procedure Set_Subject
  127. (ES : in out Structure;
  128. Subject : in String;
  129. Charset : in Character_Set := US_ASCII);
  130. -- Add a Subject to the email.
  131. procedure Set_Text_Part
  132. (ES : in out Structure;
  133. Part : in String;
  134. Charset : in Character_Set := US_ASCII);
  135. -- Add the Text part to an email.
  136. end Yolk.Email.Composer;