[성현모] KeficoMailService 추가, KMS 인증서 컨피그 추가

This commit is contained in:
SHM
2026-02-23 10:29:45 +09:00
parent 3f94a7b2b2
commit e60d499fa3
22 changed files with 445 additions and 19 deletions

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KeficoMailService
{
public class Address
{
public string AddressMail { get; set; } = string.Empty;
public string AddressName { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KeficoMailService
{
public class HtmlFormType
{
public string FormType { get; set; } = string.Empty;
public string SystemName { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{63FF04EE-D1A5-4406-9267-1EE1E9FBB9E7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KeficoMailService</RootNamespace>
<AssemblyName>KeficoMailService</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Address.cs" />
<Compile Include="HtmlFormType.cs" />
<Compile Include="MailType.cs" />
<Compile Include="Manager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KeficoMailService
{
public enum MailType
{
Text,
Html
}
}

View File

@ -0,0 +1,163 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace KeficoMailService
{
public class Manager
{
public string Host { get; set; } = "https://service.kefico.co.kr";
public readonly string GetFormHTML = "/KEFICO.XML/MAIL/MailManager.asmx";
public readonly string SendMailDetailHTML = "/KEFICO.XML/MAIL/MailManager.asmx";
public string GetFormHtml(HtmlFormType formType)
{
string result = string.Empty;
string url = $"{Host}{GetFormHTML}";
string soapEnvelope = $@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">
<soap12:Body>
<GetFormHTML xmlns=""http://kefico.co.kr/"">
<Type>
<SystemName>{formType.SystemName}</SystemName>
<FormType>{formType.FormType}</FormType>
</Type>
</GetFormHTML>
</soap12:Body>
</soap12:Envelope>";
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"Request URL: {url}");
Console.WriteLine($"Request soap: {soapEnvelope}");
byte[] data = Encoding.UTF8.GetBytes(soapEnvelope);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/soap+xml; charset=utf-8";
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
using (WebResponse response = request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
result = reader.ReadToEnd();
//decode
XDocument doc = XDocument.Parse(result);
XNamespace ns = "http://kefico.co.kr/";
string htmlEncoded =
doc.Descendants(ns + "GetFormHTMLResult").First().Value;
// HTML Decode
result = WebUtility.HtmlDecode(htmlEncoded);
result = WebUtility.HtmlDecode(htmlEncoded);
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("");
Console.WriteLine("Response");
Console.WriteLine(result);
}
return result;
}
public string SendMailDetail(Address from, List<Address> to, List<Address> cc, List<Address> bcc, string subject, string body, MailType type)
{
string result = string.Empty;
string url = $"{Host}{SendMailDetailHTML}";
string soapEnvelope = $@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">
<soap12:Body>
<SendMailDetail xmlns=""http://kefico.co.kr/"">
<From>
<AddressMail>{from.AddressMail}</AddressMail>
<AddressName>{from.AddressName}</AddressName>
</From>
<To>{string.Join("",to.Select(x=> $@"
<Address>
<AddressMail>{x.AddressMail}</AddressMail>
<AddressName>{x.AddressName}</AddressName>
</Address>"))}
</To>
<CC>{string.Join("",cc.Select(x => $@"
<Address>
<AddressMail>{x.AddressMail}</AddressMail>
<AddressName>{x.AddressName}</AddressName>
</Address>"))}
</CC>
<Bcc>{string.Join("", bcc.Select(x => $@"
<Address>
<AddressMail>{x.AddressMail}</AddressMail>
<AddressName>{x.AddressName}</AddressName>
</Address>"))}
</Bcc>
<Title>{subject}</Title>
<Body>{body}</Body>
<Type>{type.ToString()}</Type>
</SendMailDetail>
</soap12:Body>
</soap12:Envelope>";
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("");
Console.WriteLine($"Request URL: {url}");
Console.WriteLine($"Request soap: {soapEnvelope}");
byte[] data = Encoding.UTF8.GetBytes(soapEnvelope);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/soap+xml; charset=utf-8";
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
using (WebResponse response = request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
result = reader.ReadToEnd();
//decode
XDocument doc = XDocument.Parse(result);
XNamespace ns = "http://kefico.co.kr/";
string htmlEncoded =
doc.Descendants(ns + "SendMailDetailResponse").First().Value;
//decode
result = WebUtility.HtmlDecode(htmlEncoded);
result = WebUtility.HtmlDecode(result);
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("");
Console.WriteLine("Response");
Console.WriteLine(result);
}
return result;
}
}
}

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("KeficoMailService")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KeficoMailService")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("63ff04ee-d1a5-4406-9267-1ee1e9fbb9e7")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]