How to test asp.net email is being sent

后端 未结 7 1529
再見小時候
再見小時候 2021-02-09 16:11

I have some code in my asp.net which sends an email:

public void SendEmail(string message)
{
    var body = message;

    var email = new MailMessage(Configurati         


        
7条回答
  •  隐瞒了意图╮
    2021-02-09 16:32

    There is a very simple way to test the resulting email in approvaltests. You need to separate the method into 2 methods, one that creates the email, one that sends the email. Then you can call.

    EmailApprovals.Verify(mail)
    

    There's a video showing the process here: http://www.youtube.com/watch?v=Sf16dPq2n3w

提交回复
热议问题