닷넷관련/ASP.NET MVC 🍕

asp.net mvc : debugmail.io — 이메일 테스트를 위한 가짜 SMTP 서버

재우니 2022. 12. 17. 02:34

Fake SMTP server for testing emails (이메일 테스트를 위한 가짜 SMTP 서버)

 

 

Setting up an email server for testing is usually associated with headaches. Lots of environments, difficult collaboration, a risk of sending emails to real users tend to produce a great mess.

 

테스트를 위해 이메일 서버를 설정하는 것은 일반적으로 어려움이 있으며, 이는 많은 환경, 어려운 협업, 실제 사용자에게 이메일을 보낼 위험이 큰 이슈를 만드는 경향이 있습니다.

 

이를 위해 실제 메일 송수신을 처리하지 않고 fake 로 발송된 것처럼 꾸며서 개발환경에서 테스트 할 수 있도록 하는 부분입니다.

 

무에서는 web.config 에 실제 발송되도록 smtp 의 host 및 port 에 맞게 설정값을 변경해서 발송해야겠죠?

 

 

가짜 SMTP 서버 중에 이를 무료로 서비스해 주는 debugmail.io 사이트에 회원가입하여 사용해 보도록 하겠습니다.

 

https://debugmail.io/ 를 가입하고 나서, 프로젝트를 만들게 되면, settings 서브메뉴를 보시게 됩니다. 이를 선택하면 아이이디와 비밀번호를 제공해 줍니다.

 

 

 

개발 환경에서 이를 발송하게 되면, 제목, 내용을 포함하여 제대로 발송되었는지 확인할 수 있습니다. 이는 fake 이므로 실제 메일이 송수신이 되지 않고 이력만 보여줍니다.

 

 

 

<web.config> 환경설정 내용

<configuration>
	<system.net>
		<mailSettings>
			<smtp from="john.doe@example.org">
				<network defaultCredentials="false"
				         host="app.debugmail.io"
				         port="25"
				         userName="cd666c55-c50c-4589-8c5c-f251b0aabedc"
				         password="a77e37e7-e884-43a1-a885-8391a7bc6bee"
				         enableSsl="false" />
			</smtp>
		</mailSettings>
	</system.net>
</configuration>

 

asp.net mvc 에서 web.config 의 노드 접근을 해서 값을 얻기 위해 SmtpSection 클래스를 통해 노드 접근하여 값을 얻을 수 있습니다.

 

public ActionResult Index()
{

    SmtpSection smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");

    SmtpClient smtpClients = new SmtpClient(smtpSection.Network.Host, smtpSection.Network.Port);

    smtpClients.Credentials = new System.Net.NetworkCredential(smtpSection.Network.UserName, smtpSection.Network.Password);
    //smtpClients.UseDefaultCredentials = false; // uncomment if you don't want to use the network credentials
    smtpClients.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtpClients.EnableSsl = false;
    MailMessage mail = new MailMessage();

    //Setting From , To and CC
    mail.From = new MailAddress("john.doe@example.org", "MyWeb Site");
    mail.To.Add(new MailAddress("luckshim@kakao.com"));
    //mail.CC.Add(new MailAddress("MyEmailID@gmail.com"));

    mail.Subject = "이것은 제목입니다.";
    mail.SubjectEncoding = System.Text.Encoding.UTF8;
    mail.Body = "동해물과 백두산이 abcd  !@#%$#%$ 마르고 닳도록";
    mail.BodyEncoding = System.Text.Encoding.UTF8;
    mail.Priority = MailPriority.High;


    smtpClients.Send(mail);

    return View();
}

 

 

debugmail.io 사이트

 

https://debugmail.io/

 

How to send email in ASP.NET C#

 

https://stackoverflow.com/questions/18326738/how-to-send-email-in-asp-net-c-sharp

 

How to send email in ASP.NET C#

I'm very new to the ASP.NET C# area. I'm planning to send a mail through ASP.NET C# and this is the SMTP address from my ISP: smtp-proxy.tm.net.my Below is what I tried to do, but failed. <%...

stackoverflow.com