Skip to content

Commit 5f7122d

Browse files
committed
SMTPChannel and SMTPLogger example
1 parent bc8f7e8 commit 5f7122d

14 files changed

Lines changed: 924 additions & 1 deletion

‎Net/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ objects = \
2929
MailRecipient MailMessage MailStream SMTPClientSession POP3ClientSession \
3030
RawSocket RawSocketImpl ICMPClient ICMPEventArgs ICMPPacket ICMPPacketImpl \
3131
ICMPSocket ICMPSocketImpl ICMPv4PacketImpl \
32-
RemoteSyslogChannel RemoteSyslogListener \
32+
RemoteSyslogChannel RemoteSyslogListener SMTPChannel \
3333
AsyncSocketChannel
3434

3535
target = PocoNet

‎Net/Net_vs71.vcproj‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,9 @@
906906
<File
907907
RelativePath=".\include\Poco\Net\RemoteSyslogListener.h">
908908
</File>
909+
<File
910+
RelativePath=".\include\Poco\Net\SMTPChannel.h">
911+
</File>
909912
</Filter>
910913
<Filter
911914
Name="Source Files"
@@ -916,6 +919,9 @@
916919
<File
917920
RelativePath=".\src\RemoteSyslogListener.cpp">
918921
</File>
922+
<File
923+
RelativePath=".\src\SMTPChannel.cpp">
924+
</File>
919925
</Filter>
920926
</Filter>
921927
<Filter

‎Net/Net_vs80.vcproj‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,10 @@
11851185
RelativePath=".\include\Poco\Net\RemoteSyslogListener.h"
11861186
>
11871187
</File>
1188+
<File
1189+
RelativePath=".\include\Poco\Net\SMTPChannel.h"
1190+
>
1191+
</File>
11881192
</Filter>
11891193
<Filter
11901194
Name="Source Files"
@@ -1197,6 +1201,10 @@
11971201
RelativePath=".\src\RemoteSyslogListener.cpp"
11981202
>
11991203
</File>
1204+
<File
1205+
RelativePath=".\src\SMTPChannel.cpp"
1206+
>
1207+
</File>
12001208
</Filter>
12011209
</Filter>
12021210
<Filter

‎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/Main/Net/include/Poco/Net/SMTPChannel.h#4 $
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

‎Net/samples/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ projects:
1919
$(MAKE) -C EchoServer $(MAKECMDGOALS)
2020
$(MAKE) -C Mail $(MAKECMDGOALS)
2121
$(MAKE) -C Ping $(MAKECMDGOALS)
22+
$(MAKE) -C SMTPLogger $(MAKECMDGOALS)

‎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)