backport SMTPLogger

This commit is contained in:
Marian Krivos 2012-06-26 12:33:34 +00:00
parent e60cb0f58e
commit 144817e28c
10 changed files with 1480 additions and 0 deletions

View File

@ -0,0 +1,130 @@
//
// SMTPChannel.h
//
// $Id: //poco/svn/Net/include/Poco/Net/SMTPChannel.h#1 $
//
// 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

View File

@ -0,0 +1,8 @@
set(SAMPLE_NAME "SMTPLogger")
set(LOCAL_SRCS "")
aux_source_directory(src LOCAL_SRCS)
add_executable( ${SAMPLE_NAME} ${LOCAL_SRCS} )
#set_target_properties( ${SAMPLE_NAME} PROPERTIES COMPILE_FLAGS ${RELEASE_CXX_FLAGS} )
target_link_libraries( ${SAMPLE_NAME} PocoNet PocoUtil PocoXML PocoFoundation )

View 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

View File

@ -0,0 +1,8 @@
#
# sample.vmsbuild
#
# $Id: //poco/Main/Net/samples/SMTPLogger/SMTPLogger.vmsbuild#1 $
#
EXE=SMTPLogger
SMTPLogger
<SourceFilesHere>

View File

@ -0,0 +1,237 @@
<?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/$(ProjectName)d.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/$(ProjectName).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"
OutputFile="bin/$(ProjectName)mtd.exe"
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"
OutputFile="bin/$(ProjectName)mt.exe"
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>

View File

@ -0,0 +1,387 @@
<?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/$(ProjectName)d.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/$(ProjectName).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>
<Configuration
Name="debug_static|Win32"
OutputDirectory=".\obj\debug_static"
IntermediateDirectory=".\obj\debug_static"
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_STATIC;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="PocoFoundationmtd.lib PocoNetmtd.lib ws2_32.lib iphlpapi.lib advapi32.lib"
OutputFile="bin/$(ProjectName)mtd.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_static|Win32"
OutputDirectory=".\obj\release_static"
IntermediateDirectory=".\obj\release_static"
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_STATIC;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="PocoFoundationmt.lib PocoNetmt.lib ws2_32.lib iphlpapi.lib advapi32.lib"
OutputFile="bin/$(ProjectName)mt.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>

View File

@ -0,0 +1,384 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="SMTPLogger"
ProjectGUID="{5194085E-A629-4021-B908-BA02101B5B9B}"
RootNamespace="Mail"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<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/$(ProjectName)d.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/SMTPLoggerd.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<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/$(ProjectName).exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="debug_static|Win32"
OutputDirectory=".\obj\debug_static"
IntermediateDirectory=".\obj\debug_static"
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_STATIC;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="PocoFoundationmtd.lib PocoNetmtd.lib ws2_32.lib iphlpapi.lib advapi32.lib"
OutputFile="bin/$(ProjectName)mtd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/SMTPLoggerd.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_static|Win32"
OutputDirectory=".\obj\release_static"
IntermediateDirectory=".\obj\release_static"
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_STATIC;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="PocoFoundationmt.lib PocoNetmt.lib ws2_32.lib iphlpapi.lib advapi32.lib"
OutputFile="bin/$(ProjectName)mt.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\SMTPLogger.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -0,0 +1,92 @@
//
// Mail.cpp
//
// $Id: //poco/svn/Net/samples/SMTPLogger/src/SMTPLogger.cpp#1 $
//
// 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;
}

217
Net/src/SMTPChannel.cpp Normal file
View File

@ -0,0 +1,217 @@
//
// SMTPChannel.cpp
//
// $Id: //poco/svn/Net/src/SMTPChannel.cpp#2 $
//
// 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