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 | |
16 | |
17 | #ifndef Net_SecureSMTPClientSession_INCLUDED |
18 | #define Net_SecureSMTPClientSession_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Net/NetSSL.h" |
22 | #include "Poco/Net/SMTPClientSession.h" |
23 | #include "Poco/Net/Context.h" |
24 | |
25 | |
26 | namespace Poco { |
27 | namespace Net { |
28 | |
29 | |
30 | class NetSSL_API SecureSMTPClientSession: public SMTPClientSession |
31 | /// This class implements an Simple Mail |
32 | /// Transfer Protocol (SMTP, RFC 2821) |
33 | /// client for sending e-mail messages that |
34 | /// supports the STARTTLS command for secure |
35 | /// connections. |
36 | /// |
37 | /// Usage is as follows: |
38 | /// 1. Create a SecureSMTPClientSession object. |
39 | /// 2. Call login() or login(hostname). |
40 | /// 3. Call startTLS() to switch to a secure connection. |
41 | /// Check the return value to see if a secure connection |
42 | /// has actually been established (not all servers may |
43 | /// support STARTTLS). |
44 | /// 4. Call any of the login() methods to securely authenticate |
45 | /// with a username and password. |
46 | /// 5. Send the message(s). |
47 | { |
48 | public: |
49 | explicit SecureSMTPClientSession(const StreamSocket& socket); |
50 | /// Creates the SecureSMTPClientSession using |
51 | /// the given socket, which must be connected |
52 | /// to a SMTP server. |
53 | |
54 | SecureSMTPClientSession(const std::string& host, Poco::UInt16 port = SMTP_PORT); |
55 | /// Creates the SecureSMTPClientSession using a socket connected |
56 | /// to the given host and port. |
57 | |
58 | virtual ~SecureSMTPClientSession(); |
59 | /// Destroys the SMTPClientSession. |
60 | |
61 | bool startTLS(); |
62 | /// Sends a STARTTLS command and, if successful, |
63 | /// creates a secure SSL/TLS connection over the |
64 | /// existing socket connection. |
65 | /// |
66 | /// Must be called after login() or login(hostname). |
67 | /// If successful, login() can be called again |
68 | /// to authenticate the user. |
69 | /// |
70 | /// Returns true if the STARTTLS command was successful, |
71 | /// false otherwise. |
72 | |
73 | bool startTLS(Context::Ptr pContext); |
74 | /// Sends a STARTTLS command and, if successful, |
75 | /// creates a secure SSL/TLS connection over the |
76 | /// existing socket connection. |
77 | /// |
78 | /// Uses the given Context object for creating |
79 | /// the SSL/TLS connection. |
80 | /// |
81 | /// Must be called after login() or login(hostname). |
82 | /// If successful, login() can be called again |
83 | /// to authenticate the user. |
84 | /// |
85 | /// Returns true if the STARTTLS command was successful, |
86 | /// false otherwise. |
87 | |
88 | private: |
89 | std::string _host; |
90 | }; |
91 | |
92 | |
93 | } } // namespace Poco::Net |
94 | |
95 | |
96 | #endif // Net_SecureSMTPClientSession_INCLUDED |
97 | |