mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
SMTPChannel and SMTPLogger example
This commit is contained in:
parent
bc8f7e8680
commit
5f7122d21b
@ -29,7 +29,7 @@ objects = \
|
||||
MailRecipient MailMessage MailStream SMTPClientSession POP3ClientSession \
|
||||
RawSocket RawSocketImpl ICMPClient ICMPEventArgs ICMPPacket ICMPPacketImpl \
|
||||
ICMPSocket ICMPSocketImpl ICMPv4PacketImpl \
|
||||
RemoteSyslogChannel RemoteSyslogListener \
|
||||
RemoteSyslogChannel RemoteSyslogListener SMTPChannel \
|
||||
AsyncSocketChannel
|
||||
|
||||
target = PocoNet
|
||||
|
@ -906,6 +906,9 @@
|
||||
<File
|
||||
RelativePath=".\include\Poco\Net\RemoteSyslogListener.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Net\SMTPChannel.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
@ -916,6 +919,9 @@
|
||||
<File
|
||||
RelativePath=".\src\RemoteSyslogListener.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SMTPChannel.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
|
@ -1185,6 +1185,10 @@
|
||||
RelativePath=".\include\Poco\Net\RemoteSyslogListener.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Net\SMTPChannel.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
@ -1197,6 +1201,10 @@
|
||||
RelativePath=".\src\RemoteSyslogListener.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SMTPChannel.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
|
130
Net/include/Poco/Net/SMTPChannel.h
Normal file
130
Net/include/Poco/Net/SMTPChannel.h
Normal file
@ -0,0 +1,130 @@
|
||||
//
|
||||
// SMTPChannel.h
|
||||
//
|
||||
// $Id: //poco/Main/Net/include/Poco/Net/SMTPChannel.h#4 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Logging
|
||||
// Module: SMTPChannel
|
||||
//
|
||||
// Definition of the SMTPChannel class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Net_SMTPChannel_INCLUDED
|
||||
#define Net_SMTPChannel_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Channel.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
class Net_API SMTPChannel: public Poco::Channel
|
||||
/// This Channel implements SMTP (email) logging.
|
||||
{
|
||||
public:
|
||||
SMTPChannel();
|
||||
/// Creates a SMTPChannel.
|
||||
|
||||
SMTPChannel(const std::string& mailhost, const std::string& sender, const std::string& recipient);
|
||||
/// Creates a SMTPChannel with the given target mailhost, sender, and recipient.
|
||||
|
||||
void open();
|
||||
/// Opens the SMTPChannel.
|
||||
|
||||
void close();
|
||||
/// Closes the SMTPChannel.
|
||||
|
||||
void log(const Message& msg);
|
||||
/// Sends the message's text to the recipient.
|
||||
|
||||
void setProperty(const std::string& name, const std::string& value);
|
||||
/// Sets the property with the given value.
|
||||
///
|
||||
/// The following properties are supported:
|
||||
/// * mailhost: The SMTP server. Default is "localhost".
|
||||
/// * sender: The sender address.
|
||||
/// * recipient: The recipient address.
|
||||
/// * local: If true, local time is used. Default is true.
|
||||
/// * attachment: Filename of the file to attach.
|
||||
/// * type: Content type of the file to attach.
|
||||
/// * delete: Boolean value indicating whether to delete
|
||||
/// the attachment file after sending.
|
||||
/// * throw: Boolean value indicating whether to throw
|
||||
/// exception upon failure.
|
||||
|
||||
std::string getProperty(const std::string& name) const;
|
||||
/// Returns the value of the property with the given name.
|
||||
|
||||
static void registerChannel();
|
||||
/// Registers the channel with the global LoggingFactory.
|
||||
|
||||
static const std::string PROP_MAILHOST;
|
||||
static const std::string PROP_SENDER;
|
||||
static const std::string PROP_RECIPIENT;
|
||||
static const std::string PROP_LOCAL;
|
||||
static const std::string PROP_ATTACHMENT;
|
||||
static const std::string PROP_TYPE;
|
||||
static const std::string PROP_DELETE;
|
||||
static const std::string PROP_THROW;
|
||||
|
||||
protected:
|
||||
~SMTPChannel();
|
||||
|
||||
private:
|
||||
bool isTrue(const std::string& value) const;
|
||||
|
||||
std::string _mailHost;
|
||||
std::string _sender;
|
||||
std::string _recipient;
|
||||
bool _local;
|
||||
std::string _attachment;
|
||||
std::string _type;
|
||||
bool _delete;
|
||||
bool _throw;
|
||||
};
|
||||
|
||||
|
||||
inline bool SMTPChannel::isTrue(const std::string& value) const
|
||||
{
|
||||
return ((0 == icompare(value, "true")) ||
|
||||
(0 == icompare(value, "t")) ||
|
||||
(0 == icompare(value, "yes")) ||
|
||||
(0 == icompare(value, "y")));
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
#endif // Net_SMTPChannel_INCLUDED
|
@ -19,3 +19,4 @@ projects:
|
||||
$(MAKE) -C EchoServer $(MAKECMDGOALS)
|
||||
$(MAKE) -C Mail $(MAKECMDGOALS)
|
||||
$(MAKE) -C Ping $(MAKECMDGOALS)
|
||||
$(MAKE) -C SMTPLogger $(MAKECMDGOALS)
|
||||
|
17
Net/samples/SMTPLogger/Makefile
Normal file
17
Net/samples/SMTPLogger/Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/Main/Net/samples/SMTPLogger/Makefile#2 $
|
||||
#
|
||||
# Makefile for Poco SMTPLogger
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = SMTPLogger
|
||||
|
||||
target = SMTPLogger
|
||||
target_version = 1
|
||||
target_libs = PocoNet PocoFoundation
|
||||
|
||||
include $(POCO_BASE)/build/rules/exec
|
8
Net/samples/SMTPLogger/SMTPLogger.vmsbuild
Normal file
8
Net/samples/SMTPLogger/SMTPLogger.vmsbuild
Normal file
@ -0,0 +1,8 @@
|
||||
#
|
||||
# sample.vmsbuild
|
||||
#
|
||||
# $Id: //poco/Main/Net/samples/SMTPLogger/SMTPLogger.vmsbuild#1 $
|
||||
#
|
||||
EXE=SMTPLogger
|
||||
SMTPLogger
|
||||
<SourceFilesHere>
|
235
Net/samples/SMTPLogger/SMTPLogger_vs71.vcproj
Normal file
235
Net/samples/SMTPLogger/SMTPLogger_vs71.vcproj
Normal file
@ -0,0 +1,235 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="SMTPLogger"
|
||||
ProjectGUID="{D6C4B3D4-2026-4A33-B4DA-ABE8FF2EE0B8}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="TRUE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib PocoNetd.lib"
|
||||
OutputFile="bin/SMTPLoggerd.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="bin/SMTPLoggerd.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForWindowsApplication="TRUE"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
|
||||
OutputFile="bin/SMTPLogger.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="FALSE"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="debug_static|Win32"
|
||||
OutputDirectory="obj\debug_static"
|
||||
IntermediateDirectory="obj\debug_static"
|
||||
ConfigurationType="1">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_STATIC;WINVER=0x0500"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="TRUE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationmtd.lib PocoXMLmtd.lib PocoNetmtd.lib PocoUtilmtd.lib ws2_32.lib"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="bin/SMTPLoggermtd.pdb"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_static|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_STATIC;WINVER=0x0500"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationmt.lib PocoXMLmt.lib PocoNetmt.lib PocoUtilmt.lib ws2_32.lib"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\SMTPLogger.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
210
Net/samples/SMTPLogger/SMTPLogger_vs80.vcproj
Normal file
210
Net/samples/SMTPLogger/SMTPLogger_vs80.vcproj
Normal file
@ -0,0 +1,210 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="SMTPLogger"
|
||||
ProjectGUID="{5194085E-A629-4021-B908-BA02101B5B9B}"
|
||||
RootNamespace="Mail"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="true"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib PocoNetd.lib"
|
||||
OutputFile="bin/SMTPLoggerd.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="bin/SMTPLoggerd.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="false"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib PocoNet.lib"
|
||||
OutputFile="bin/SMTPLogger.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="false"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\SMTPLogger.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
BIN
Net/samples/SMTPLogger/logo.gif
Normal file
BIN
Net/samples/SMTPLogger/logo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
92
Net/samples/SMTPLogger/src/SMTPLogger.cpp
Normal file
92
Net/samples/SMTPLogger/src/SMTPLogger.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
//
|
||||
// Mail.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/samples/EmailLogger/src/EmailLogger.cpp#6 $
|
||||
//
|
||||
// This sample demonstrates the SMTPChannel class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Net/MailMessage.h"
|
||||
#include "Poco/Net/SMTPChannel.h"
|
||||
#include "Poco/Logger.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::SMTPChannel;
|
||||
using Poco::Logger;
|
||||
using Poco::Path;
|
||||
using Poco::AutoPtr;
|
||||
using Poco::Exception;
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
const std::string fileName = "${POCO_BASE}/Net/samples/SMTPLogger/logo.gif";
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
const std::string fileName = "%POCO_BASE%/Net/samples/SMTPLogger/logo.gif";
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 4)
|
||||
{
|
||||
Path p(argv[0]);
|
||||
std::cerr << "usage: " << p.getBaseName() << " <mailhost> <sender> <recipient>" << std::endl;
|
||||
std::cerr << " Send an email log entry from <sender> to <recipient>," << std::endl;
|
||||
std::cerr << " the SMTP server at <mailhost>." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string mailhost(argv[1]);
|
||||
std::string sender(argv[2]);
|
||||
std::string recipient(argv[3]);
|
||||
std::string attachment = Path::expand(fileName);
|
||||
|
||||
try
|
||||
{
|
||||
AutoPtr<SMTPChannel> pSMTPChannel = new SMTPChannel(mailhost, sender, recipient);
|
||||
pSMTPChannel->setProperty("attachment", attachment);
|
||||
pSMTPChannel->setProperty("type", "image/gif");
|
||||
pSMTPChannel->setProperty("delete", "false");
|
||||
pSMTPChannel->setProperty("throw", "true");
|
||||
|
||||
Logger& logger = Logger::get("POCO Sample SMTP Logger");
|
||||
logger.setChannel(pSMTPChannel.get());
|
||||
logger.critical("Critical message");
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
std::cerr << exc.displayText() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -39,6 +39,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HTTPFormServer", "HTTPFormS
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SMTPLogger", "SMTPLogger\SMTPLogger_vs71.vcproj", "{D6C4B3D4-2026-4A33-B4DA-ABE8FF2EE0B8}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
debug_shared = debug_shared
|
||||
@ -129,6 +133,14 @@ Global
|
||||
{45A054E6-44EC-4943-809A-BA8B2A25DA21}.release_shared.Build.0 = release_shared|Win32
|
||||
{45A054E6-44EC-4943-809A-BA8B2A25DA21}.release_static.ActiveCfg = release_static|Win32
|
||||
{45A054E6-44EC-4943-809A-BA8B2A25DA21}.release_static.Build.0 = release_static|Win32
|
||||
{D6C4B3D4-2026-4A33-B4DA-ABE8FF2EE0B8}.debug_shared.ActiveCfg = debug_shared|Win32
|
||||
{D6C4B3D4-2026-4A33-B4DA-ABE8FF2EE0B8}.debug_shared.Build.0 = debug_shared|Win32
|
||||
{D6C4B3D4-2026-4A33-B4DA-ABE8FF2EE0B8}.debug_static.ActiveCfg = debug_static|Win32
|
||||
{D6C4B3D4-2026-4A33-B4DA-ABE8FF2EE0B8}.debug_static.Build.0 = debug_static|Win32
|
||||
{D6C4B3D4-2026-4A33-B4DA-ABE8FF2EE0B8}.release_shared.ActiveCfg = release_shared|Win32
|
||||
{D6C4B3D4-2026-4A33-B4DA-ABE8FF2EE0B8}.release_shared.Build.0 = release_shared|Win32
|
||||
{D6C4B3D4-2026-4A33-B4DA-ABE8FF2EE0B8}.release_static.ActiveCfg = release_static|Win32
|
||||
{D6C4B3D4-2026-4A33-B4DA-ABE8FF2EE0B8}.release_static.Build.0 = release_static|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
|
@ -20,6 +20,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ping", "Ping\Ping_vs80.vcpr
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HTTPFormServer", "HTTPFormServer\HTTPFormServer_vs80.vcproj", "{5363487F-1F23-4F9E-B6A7-5471B0F2373F}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SMTPLogger", "SMTPLogger\SMTPLogger_vs80.vcproj", "{5194085E-A629-4021-B908-BA02101B5B9B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
debug_shared|Win32 = debug_shared|Win32
|
||||
@ -66,6 +68,10 @@ Global
|
||||
{5363487F-1F23-4F9E-B6A7-5471B0F2373F}.debug_shared|Win32.Build.0 = debug_shared|Win32
|
||||
{5363487F-1F23-4F9E-B6A7-5471B0F2373F}.release_shared|Win32.ActiveCfg = release_shared|Win32
|
||||
{5363487F-1F23-4F9E-B6A7-5471B0F2373F}.release_shared|Win32.Build.0 = release_shared|Win32
|
||||
{5194085E-A629-4021-B908-BA02101B5B9B}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
|
||||
{5194085E-A629-4021-B908-BA02101B5B9B}.debug_shared|Win32.Build.0 = debug_shared|Win32
|
||||
{5194085E-A629-4021-B908-BA02101B5B9B}.release_shared|Win32.ActiveCfg = release_shared|Win32
|
||||
{5194085E-A629-4021-B908-BA02101B5B9B}.release_shared|Win32.Build.0 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
198
Net/src/SMTPChannel.cpp
Normal file
198
Net/src/SMTPChannel.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
//
|
||||
// SMTPChannel.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/src/SMTPChannel.cpp#3 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Logging
|
||||
// Module: SMTPChannel
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Net/SMTPChannel.h"
|
||||
#include "Poco/Net/MailMessage.h"
|
||||
#include "Poco/Net/MailRecipient.h"
|
||||
#include "Poco/Net/SMTPClientSession.h"
|
||||
#include "Poco/Net/StringPartSource.h"
|
||||
#include "Poco/Message.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "Poco/LocalDateTime.h"
|
||||
#include "Poco/LoggingFactory.h"
|
||||
#include "Poco/Instantiator.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Environment.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
const std::string SMTPChannel::PROP_MAILHOST("mailhost");
|
||||
const std::string SMTPChannel::PROP_SENDER("sender");
|
||||
const std::string SMTPChannel::PROP_RECIPIENT("recipient");
|
||||
const std::string SMTPChannel::PROP_LOCAL("local");
|
||||
const std::string SMTPChannel::PROP_ATTACHMENT("attachment");
|
||||
const std::string SMTPChannel::PROP_TYPE("type");
|
||||
const std::string SMTPChannel::PROP_DELETE("delete");
|
||||
const std::string SMTPChannel::PROP_THROW("throw");
|
||||
|
||||
|
||||
SMTPChannel::SMTPChannel():
|
||||
_mailHost("localhost"),
|
||||
_local(true),
|
||||
_type("text/plain"),
|
||||
_delete(false),
|
||||
_throw(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SMTPChannel::SMTPChannel(const std::string& mailhost, const std::string& sender, const std::string& recipient):
|
||||
_mailHost(mailhost),
|
||||
_sender(sender),
|
||||
_recipient(recipient),
|
||||
_local(true),
|
||||
_type("text/plain"),
|
||||
_delete(false),
|
||||
_throw(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SMTPChannel::~SMTPChannel()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void SMTPChannel::open()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SMTPChannel::close()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SMTPChannel::log(const Message& msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
MailMessage message;
|
||||
message.setSender(_sender);
|
||||
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, _recipient));
|
||||
message.setSubject("Log Message from " + _sender);
|
||||
std::stringstream content;
|
||||
content << "Log Message\r\n"
|
||||
<< "===========\r\n\r\n"
|
||||
<< "Host: " << Environment::nodeName() << "\r\n"
|
||||
<< "Logger: " << msg.getSource() << "\r\n";
|
||||
|
||||
if (_local)
|
||||
{
|
||||
DateTime dt(msg.getTime());
|
||||
content << "Timestamp: " << DateTimeFormatter::format(LocalDateTime(dt), DateTimeFormat::RFC822_FORMAT) << "\r\n";
|
||||
}
|
||||
else
|
||||
content << "Timestamp: " << DateTimeFormatter::format(msg.getTime(), DateTimeFormat::RFC822_FORMAT) << "\r\n";
|
||||
|
||||
content << "Priority: " << NumberFormatter::format(msg.getPriority()) << "\r\n"
|
||||
<< "Process ID: " << NumberFormatter::format(msg.getPid()) << "\r\n"
|
||||
<< "Thread: " << msg.getThread() << " (ID: " << msg.getTid() << ")\r\n"
|
||||
<< "Message text: " << msg.getText() << "\r\n\r\n";
|
||||
|
||||
message.addContent(new StringPartSource(content.str()));
|
||||
|
||||
if (!_attachment.empty())
|
||||
{
|
||||
{
|
||||
Poco::FileInputStream fis(_attachment, std::ios::in | std::ios::binary | std::ios::ate);
|
||||
if (fis.good())
|
||||
{
|
||||
int size = fis.tellg();
|
||||
char* pMem = new char [size];
|
||||
fis.seekg(std::ios::beg);
|
||||
fis.read(pMem, size);
|
||||
message.addAttachment(_attachment, new StringPartSource(std::string(pMem, size), _type, _attachment));
|
||||
delete [] pMem;
|
||||
}
|
||||
}
|
||||
if (_delete) File(_attachment).remove();
|
||||
}
|
||||
|
||||
SMTPClientSession session(_mailHost);
|
||||
session.login();
|
||||
session.sendMessage(message);
|
||||
session.close();
|
||||
} catch(Exception&)
|
||||
{
|
||||
if (_throw) throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SMTPChannel::setProperty(const std::string& name, const std::string& value)
|
||||
{
|
||||
if (name == PROP_MAILHOST) _mailHost = value;
|
||||
else if (name == PROP_SENDER) _sender = value;
|
||||
else if (name == PROP_RECIPIENT) _recipient = value;
|
||||
else if (name == PROP_LOCAL) _local = isTrue(value);
|
||||
else if (name == PROP_ATTACHMENT) _attachment = value;
|
||||
else if (name == PROP_TYPE) _type = value;
|
||||
else if (name == PROP_DELETE) _delete = isTrue(value);
|
||||
else if (name == PROP_THROW) _throw = isTrue(value);
|
||||
else Channel::setProperty(name, value);
|
||||
}
|
||||
|
||||
|
||||
std::string SMTPChannel::getProperty(const std::string& name) const
|
||||
{
|
||||
if (name == PROP_MAILHOST) return _mailHost;
|
||||
else if (name == PROP_SENDER) return _sender;
|
||||
else if (name == PROP_RECIPIENT) return _recipient;
|
||||
else if (name == PROP_LOCAL) return _local ? "true" : "false";
|
||||
else if (name == PROP_ATTACHMENT) return _attachment;
|
||||
else if (name == PROP_TYPE) return _type;
|
||||
else if (name == PROP_DELETE) return _delete ? "true" : "false";
|
||||
else if (name == PROP_THROW) return _throw ? "true" : "false";
|
||||
else return Channel::getProperty(name);
|
||||
}
|
||||
|
||||
|
||||
void SMTPChannel::registerChannel()
|
||||
{
|
||||
Poco::LoggingFactory::defaultFactory().registerChannelClass("SMTPChannel",
|
||||
new Poco::Instantiator<SMTPChannel, Poco::Channel>);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
Loading…
Reference in New Issue
Block a user