How to test asp.net email is being sent

后端 未结 7 1556
再見小時候
再見小時候 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:24

    http://ssfd.codeplex.com/

    0 讨论(0)
  • 2021-02-09 16:30

    You can use SMTP4Dev

    http://smtp4dev.codeplex.com/

    Just install it (it's a little program that runs in your task bar). No configuration is required from your development program end...

    By default, I think it will just work with your code unmodified as it listens on your local host.

    You'll get a nice taskbar popup notification when you send emails... just click on the notification to look at the actual contents of the email!

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-02-09 16:37

    to setup an automated test you'll want to have a test email address on a server you can query (since topic is asp.net, we'll assume exchange server), then query the mailbox for the email you're looking for using:

    opt 1: exchange sdk

    opt 2: through web requests (if the exchange server's http connector is enabled

    opt 3: write your own simple pop3 client/cli/api

    ref for opt 3: http://www.codeproject.com/KB/IP/popapp.aspx

    0 讨论(0)
  • 2021-02-09 16:41

    Send an email to yourself and see if you received it?

    If you don't know how to do that you probably want to go back to basics.

    0 讨论(0)
  • 2021-02-09 16:43

    Just create a folder called "maildrop" on your c:/ drive and use the following in your Web.config file:

    <mailSettings>
        <smtp deliveryMethod='SpecifiedPickupDirectory'>
            <specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop" />
        </smtp>
    </mailSettings>
    

    More information:

    http://weblogs.asp.net/gunnarpeipman/archive/2010/05/27/asp-net-using-pickup-directory-for-outgoing-e-mails.aspx

    0 讨论(0)
提交回复
热议问题