1//
2// SMTPChannel.h
3//
4// Library: Net
5// Package: Logging
6// Module: SMTPChannel
7//
8// Definition of the SMTPChannel class.
9//
10// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Net_SMTPChannel_INCLUDED
18#define Net_SMTPChannel_INCLUDED
19
20
21#include "Poco/Net/Net.h"
22#include "Poco/Channel.h"
23#include "Poco/String.h"
24
25
26namespace Poco {
27namespace Net {
28
29
30class Net_API SMTPChannel: public Poco::Channel
31 /// This Channel implements SMTP (email) logging.
32{
33public:
34 SMTPChannel();
35 /// Creates a SMTPChannel.
36
37 SMTPChannel(const std::string& mailhost, const std::string& sender, const std::string& recipient);
38 /// Creates a SMTPChannel with the given target mailhost, sender, and recipient.
39
40 void open();
41 /// Opens the SMTPChannel.
42
43 void close();
44 /// Closes the SMTPChannel.
45
46 void log(const Message& msg);
47 /// Sends the message's text to the recipient.
48
49 void setProperty(const std::string& name, const std::string& value);
50 /// Sets the property with the given value.
51 ///
52 /// The following properties are supported:
53 /// * mailhost: The SMTP server. Default is "localhost".
54 /// * sender: The sender address.
55 /// * recipient: The recipient address.
56 /// * local: If true, local time is used. Default is true.
57 /// * attachment: Filename of the file to attach.
58 /// * type: Content type of the file to attach.
59 /// * delete: Boolean value indicating whether to delete
60 /// the attachment file after sending.
61 /// * throw: Boolean value indicating whether to throw
62 /// exception upon failure.
63
64 std::string getProperty(const std::string& name) const;
65 /// Returns the value of the property with the given name.
66
67 static void registerChannel();
68 /// Registers the channel with the global LoggingFactory.
69
70 static const std::string PROP_MAILHOST;
71 static const std::string PROP_SENDER;
72 static const std::string PROP_RECIPIENT;
73 static const std::string PROP_LOCAL;
74 static const std::string PROP_ATTACHMENT;
75 static const std::string PROP_TYPE;
76 static const std::string PROP_DELETE;
77 static const std::string PROP_THROW;
78
79protected:
80 ~SMTPChannel();
81
82private:
83 bool isTrue(const std::string& value) const;
84
85 std::string _mailHost;
86 std::string _sender;
87 std::string _recipient;
88 bool _local;
89 std::string _attachment;
90 std::string _type;
91 bool _delete;
92 bool _throw;
93};
94
95
96inline bool SMTPChannel::isTrue(const std::string& value) const
97{
98 return ((0 == icompare(value, "true")) ||
99 (0 == icompare(value, "t")) ||
100 (0 == icompare(value, "yes")) ||
101 (0 == icompare(value, "y")));
102}
103
104
105} } // namespace Poco::Net
106
107
108#endif // Net_SMTPChannel_INCLUDED
109