메일서비스 로그 강화 및 오류 처리

This commit is contained in:
ChiKyun Kim
2025-08-12 17:10:34 +09:00
parent 9725ae55d0
commit de5a759902

View File

@@ -1213,7 +1213,7 @@ namespace Console_SendMail
public static void SendMail()
{
var timestr = DateTime.Now.ToString("yyMMddHHmmss");
//메일서버역할이 있다.
try
{
@@ -1234,6 +1234,8 @@ namespace Console_SendMail
var subject = string.Empty;// getdbdata(dar["subject"]).Trim();
var body = string.Empty;//getdbdata(dar["body"]).Trim();
var idx = -1;
var pdate = string.Empty;
while (dar.Read())
@@ -1243,6 +1245,7 @@ namespace Console_SendMail
list_bcc = getMaillist(dar["bcc"]);
list_cc = getMaillist(dar["cc"]);
pdate = dar["wdate"].ToString();
subject = getdbdata(dar["subject"]).Trim();
body = getdbdata(dar["body"]).Trim();
idx = (int)dar["idx"];
@@ -1250,25 +1253,26 @@ namespace Console_SendMail
dar.Close();
string sendMsg = "";
if (list_from == "")
if (string.IsNullOrEmpty(list_from))
{
sendMsg = ("보내는 주소가 없습니다");
}
else if (subject.Trim() == "")
else if (string.IsNullOrEmpty(subject.Trim()))
{
sendMsg = ("메일 제목이 없습니다");
}
else if (body.Trim() == "")
else if (string.IsNullOrEmpty(body.Trim()))
{
sendMsg = ("본문이 없습니다");
}
else if (list_to == "")
else if (string.IsNullOrEmpty(list_to.Trim()))
{
sendMsg = ("받는 주소가 없습니다");
}
if (idx > 0)
{
//오류메시지가 있다면 업데이트만 한다
if (string.IsNullOrWhiteSpace(sendMsg) == false)
{
//오류가 있다
@@ -1284,9 +1288,14 @@ namespace Console_SendMail
//Console.WriteLine(string.Format("Send Complete index={0},Msg={1}", dar["idx"], sendMsg));
//ta.UpdateSendOK(sendMsg, dr.idx);
var ucnt = cmd.ExecuteNonQuery();
Console.Write($"[{timestr}]-IDX:{idx} [{pdate}] ErrorMessage Update Subject:{getdbdata(subject)} Messqage:{sendMsg}");
if (ucnt == 1)
{
Console.WriteLine("send mail to" + list_to + ",subject=" + getdbdata(subject));
Console.WriteLine($" [OK]");
}
else
{
Console.WriteLine($" [ERR COUNT={ucnt}]");
}
}
catch (Exception eX)
@@ -1303,6 +1312,9 @@ namespace Console_SendMail
"<br />메일이 잘못 전송 되었다면 [<a href='chikyun.kim@amkor.co.kr'>chikyun.kim@amkor.co.kr</a>] 로 문의 주시기 바랍니다" +
"</p>";
subject = subject.Replace("\r", "").Replace("\n", "");
body = body.Replace("\r", "").Replace("\n", "");
//전송을 해야 함
var mc = new System.Net.Mail.SmtpClient("10.101.5.150");
var msg = new System.Net.Mail.MailMessage
@@ -1331,12 +1343,13 @@ namespace Console_SendMail
if (ucnt == 1)
{
mc.Send(msg);
Console.WriteLine("send mail to" + list_to + ",subject=" + getdbdata(subject));
Console.WriteLine($"[{timestr}]-IDX:{idx} [{pdate}] send mail to [" + list_to + "],subject=" + getdbdata(subject));
}
}
catch (Exception eX)
{
Console.WriteLine("[sendmail] : " + eX.Message);
//오류가 발생하면 해당 오류메세지로 데이터를 업데이트 해준다.
Console.WriteLine($"[{timestr}]-IDX:{idx} [sendmail] : " + eX.Message);
sendMsg = eX.Message;
msgupdate = true;
}
@@ -1354,10 +1367,11 @@ namespace Console_SendMail
var ucnt = cmd.ExecuteNonQuery();
}
}
catch
catch(Exception ex)
{
//sendMsg = eX.Message;
//msgupdate = true;
Console.WriteLine($"[{timestr}]-IDX:{idx} eror state update failed {ex.Message}");
}
}
}
@@ -1368,9 +1382,9 @@ namespace Console_SendMail
cmd.Dispose();
cn.Close();
}
catch
catch (Exception ex)
{
Console.WriteLine($"[{timestr}] [sendmail] {ex.Message}");
}
finally
{