SmtpClient.Send 오류 - net_io_connectionclosed
윈도우 서버에서 기본 제공되는 SMTP 서버를 이용하는 프로그램을 만들어서,
SmtpClient smtp = new SmtpClient();
smtp.Host = "127.0.0.1";
smtp.UseDefaultCredentials = true;
MailAddress from = new MailAddress("test@test.com");
MailAddress to = new MailAddress("...[받는 사람 이메일 주소]...");
MailMessage msg = new MailMessage(from, to);
msg.Body = "Test is good";
msg.Subject = "Test mail";
smtp.Send(msg);
실행시켰는데, 다음과 같은 오류가 발생했습니다.
C:\temp>ConsoleApplication1.exe
처리되지 않은 예외: System.Net.Mail.SmtpException: 메일을 보내지 못했습니다. ---> System.IO.IOException: 전송 연결 net_io_connectionclosed에서 데이터를 읽을 수 없습니다.
위치: System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
위치: System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
위치: System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
위치: System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
위치: System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
위치: System.Net.Mail.SmtpClient.GetConnection()
위치: System.Net.Mail.SmtpClient.Send(MailMessage message)
--- 내부 예외 스택 추적의 끝 ---
위치: System.Net.Mail.SmtpClient.Send(MailMessage message)
위치: ConsoleApplication1.Program.Main(String[] args)
SmtpClient.Host 속성에 127.0.0.1 대신 실제 IP를 입력하니 정상적으로 이메일이 발송되었습니다. 이런 경우도 다 있군요. ^^
그래서, SMTP 서버 설정에 가보니... ^^;;; IP 주소를 지정한 체로 설정되어 있었던 것입니다.
위의 값을 "(지정하지 않은 모든 IP)" - "(All Unassigned)"로 바꿔주면 127.0.0.1 주소값으로 메일이 잘 보내집니다.
가끔은, 오류의 원인을 모를 때 기본부터 확인하는 것이 좋다는! ^^
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]