Skip to content

Commit 144817e

Browse files
author
Marian Krivos
committed
backport SMTPLogger
1 parent e60cb0f commit 144817e

10 files changed

Lines changed: 1480 additions & 0 deletions

File tree

Net/include/Poco/Net/SMTPChannel.h

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
//
2+
// SMTPChannel.h
3+
//
4+
// $Id: //poco/svn/Net/include/Poco/Net/SMTPChannel.h#1 $
5+
//
6+
// Library: Net
7+
// Package: Logging
8+
// Module: SMTPChannel
9+
//
10+
// Definition of the SMTPChannel class.
11+
//
12+
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
13+
// and Contributors.
14+
//
15+
// Permission is hereby granted, free of charge, to any person or organization
16+
// obtaining a copy of the software and accompanying documentation covered by
17+
// this license (the "Software") to use, reproduce, display, distribute,
18+
// execute, and transmit the Software, and to prepare derivative works of the
19+
// Software, and to permit third-parties to whom the Software is furnished to
20+
// do so, all subject to the following:
21+
//
22+
// The copyright notices in the Software and this entire statement, including
23+
// the above license grant, this restriction and the following disclaimer,
24+
// must be included in all copies of the Software, in whole or in part, and
25+
// all derivative works of the Software, unless such copies or derivative
26+
// works are solely in the form of machine-executable object code generated by
27+
// a source language processor.
28+
//
29+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32+
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33+
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35+
// DEALINGS IN THE SOFTWARE.
36+
//
37+
38+
39+
#ifndef Net_SMTPChannel_INCLUDED
40+
#define Net_SMTPChannel_INCLUDED
41+
42+
43+
#include "Poco/Net/Net.h"
44+
#include "Poco/Channel.h"
45+
#include "Poco/String.h"
46+
47+
48+
namespace Poco {
49+
namespace Net {
50+
51+
52+
class Net_API SMTPChannel: public Poco::Channel
53+
/// This Channel implements SMTP (email) logging.
54+
{
55+
public:
56+
SMTPChannel();
57+
/// Creates a SMTPChannel.
58+
59+
SMTPChannel(const std::string& mailhost, const std::string& sender, const std::string& recipient);
60+
/// Creates a SMTPChannel with the given target mailhost, sender, and recipient.
61+
62+
void open();
63+
/// Opens the SMTPChannel.
64+
65+
void close();
66+
/// Closes the SMTPChannel.
67+
68+
void log(const Message& msg);
69+
/// Sends the message's text to the recipient.
70+
71+
void setProperty(const std::string& name, const std::string& value);
72+
/// Sets the property with the given value.
73+
///
74+
/// The following properties are supported:
75+
/// * mailhost: The SMTP server. Default is "localhost".
76+
/// * sender: The sender address.
77+
/// * recipient: The recipient address.
78+
/// * local: If true, local time is used. Default is true.
79+
/// * attachment: Filename of the file to attach.
80+
/// * type: Content type of the file to attach.
81+
/// * delete: Boolean value indicating whether to delete
82+
/// the attachment file after sending.
83+
/// * throw: Boolean value indicating whether to throw
84+
/// exception upon failure.
85+
86+
std::string getProperty(const std::string& name) const;
87+
/// Returns the value of the property with the given name.
88+
89+
static void registerChannel();
90+
/// Registers the channel with the global LoggingFactory.
91+
92+
static const std::string PROP_MAILHOST;
93+
static const std::string PROP_SENDER;
94+
static const std::string PROP_RECIPIENT;
95+
static const std::string PROP_LOCAL;
96+
static const std::string PROP_ATTACHMENT;
97+
static const std::string PROP_TYPE;
98+
static const std::string PROP_DELETE;
99+
static const std::string PROP_THROW;
100+
101+
protected:
102+
~SMTPChannel();
103+
104+
private:
105+
bool isTrue(const std::string& value) const;
106+
107+
std::string _mailHost;
108+
std::string _sender;
109+
std::string _recipient;
110+
bool _local;
111+
std::string _attachment;
112+
std::string _type;
113+
bool _delete;
114+
bool _throw;
115+
};
116+
117+
118+
inline bool SMTPChannel::isTrue(const std::string& value) const
119+
{
120+
return ((0 == icompare(value, "true")) ||
121+
(0 == icompare(value, "t")) ||
122+
(0 == icompare(value, "yes")) ||
123+
(0 == icompare(value, "y")));
124+
}
125+
126+
127+
} } // namespace Poco::Net
128+
129+
130+
#endif // Net_SMTPChannel_INCLUDED
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(SAMPLE_NAME "SMTPLogger")
2+
3+
set(LOCAL_SRCS "")
4+
aux_source_directory(src LOCAL_SRCS)
5+
6+
add_executable( ${SAMPLE_NAME} ${LOCAL_SRCS} )
7+
#set_target_properties( ${SAMPLE_NAME} PROPERTIES COMPILE_FLAGS ${RELEASE_CXX_FLAGS} )
8+
target_link_libraries( ${SAMPLE_NAME} PocoNet PocoUtil PocoXML PocoFoundation )

Net/samples/SMTPLogger/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Makefile
3+
#
4+
# $Id: //poco/Main/Net/samples/SMTPLogger/Makefile#2 $
5+
#
6+
# Makefile for Poco SMTPLogger
7+
#
8+
9+
include $(POCO_BASE)/build/rules/global
10+
11+
objects = SMTPLogger
12+
13+
target = SMTPLogger
14+
target_version = 1
15+
target_libs = PocoNet PocoFoundation
16+
17+
include $(POCO_BASE)/build/rules/exec
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# sample.vmsbuild
3+
#
4+
# $Id: //poco/Main/Net/samples/SMTPLogger/SMTPLogger.vmsbuild#1 $
5+
#
6+
EXE=SMTPLogger
7+
SMTPLogger
8+
<SourceFilesHere>

0 commit comments

Comments
 (0)