SecureSMTPClientSession.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // SecureSMTPClientSession.h
  3. //
  4. // Library: NetSSL_OpenSSL
  5. // Package: Mail
  6. // Module: SecureSMTPClientSession
  7. //
  8. // Definition of the SecureSMTPClientSession class.
  9. //
  10. // Copyright (c) 2010, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Net_SecureSMTPClientSession_INCLUDED
  16. #define Net_SecureSMTPClientSession_INCLUDED
  17. #include "Poco/Net/NetSSL.h"
  18. #include "Poco/Net/SMTPClientSession.h"
  19. #include "Poco/Net/Context.h"
  20. namespace Poco {
  21. namespace Net {
  22. class NetSSL_API SecureSMTPClientSession: public SMTPClientSession
  23. /// This class implements an Simple Mail
  24. /// Transfer Protocol (SMTP, RFC 2821)
  25. /// client for sending e-mail messages that
  26. /// supports the STARTTLS command for secure
  27. /// connections.
  28. ///
  29. /// Usage is as follows:
  30. /// 1. Create a SecureSMTPClientSession object.
  31. /// 2. Call login() or login(hostname).
  32. /// 3. Call startTLS() to switch to a secure connection.
  33. /// Check the return value to see if a secure connection
  34. /// has actually been established (not all servers may
  35. /// support STARTTLS).
  36. /// 4. Call any of the login() methods to securely authenticate
  37. /// with a username and password.
  38. /// 5. Send the message(s).
  39. {
  40. public:
  41. explicit SecureSMTPClientSession(const StreamSocket& socket);
  42. /// Creates the SecureSMTPClientSession using
  43. /// the given socket, which must be connected
  44. /// to a SMTP server.
  45. SecureSMTPClientSession(const std::string& host, Poco::UInt16 port = SMTP_PORT);
  46. /// Creates the SecureSMTPClientSession using a socket connected
  47. /// to the given host and port.
  48. virtual ~SecureSMTPClientSession();
  49. /// Destroys the SMTPClientSession.
  50. bool startTLS();
  51. /// Sends a STARTTLS command and, if successful,
  52. /// creates a secure SSL/TLS connection over the
  53. /// existing socket connection.
  54. ///
  55. /// Must be called after login() or login(hostname).
  56. /// If successful, login() can be called again
  57. /// to authenticate the user.
  58. ///
  59. /// Returns true if the STARTTLS command was successful,
  60. /// false otherwise.
  61. bool startTLS(Context::Ptr pContext);
  62. /// Sends a STARTTLS command and, if successful,
  63. /// creates a secure SSL/TLS connection over the
  64. /// existing socket connection.
  65. ///
  66. /// Uses the given Context object for creating
  67. /// the SSL/TLS connection.
  68. ///
  69. /// Must be called after login() or login(hostname).
  70. /// If successful, login() can be called again
  71. /// to authenticate the user.
  72. ///
  73. /// Returns true if the STARTTLS command was successful,
  74. /// false otherwise.
  75. private:
  76. std::string _host;
  77. };
  78. } } // namespace Poco::Net
  79. #endif // Net_SecureSMTPClientSession_INCLUDED