A lot of the time when developing apps, you need to send emails from your application. Developers need a way to test this and sometimes setting up a SMTP server is a little overkill. Thankfully, the .NET framework has a built in way for you to set this up so you can send the emails to your hard drive as opposed to a SMTP server.
Simply add the following code to your web.config or app.config...
Code Snippet
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\" />
</smtp>
</mailSettings>
</system.net>
Usage:
Code Snippet
System.Net.Mail.MailMessage mail
= new System.Net.Mail.MailMessage("fromEmail@email.com",
"toEmail@email.com", "Test", "Test Body");
System.Net.Mail.SmtpClient client
= new System.Net.Mail.SmtpClient();
client.Send(mail);
No comments:
Post a Comment