- Why Johnny Can’t do Test Driven Development
- Excuses For Not Testing
- Why Start A Blog?
- Being Agile Is About The Journey…
- NUnit Test Code Structure
- Software Architecture without Test Driven Development is DANGEROUS!
- You Aren’t Doing Scrum If…
- Selenium Grid Setup
- SpecFlow Strategy
- Responsive Web Design Conversion
- Magic Strings and Magic Numbers
- String and StringBuilder
- NUnit & Visual Studio
- Value Type vs Reference Type
Is Your Architecture Crippling Your Unit Testing?
DotNetNuke Tweak FOR SEO
Extension Methods in CSharp
Easily Find Classes, Methods, and Variables
Type Safe Session Variables
DotNetNuke - Modules - Creating Stored Procs
Git, Gitosis, Putty and Windows
YAGNI - You Aren’t Going To Need It
Bypass VPN for regular traffic
Unique SQL Logins and SqlMembership Provider
Test Sending Email without a Server in ASP.NET
You can also get the feed via email. Sign up now by supplying your email address and clicking the Subscribe button
By now, most people are familiar with the fact that ASP.NET will send mail from the codebehind by simply adding a few lines to your web.config file and adding another few lines of code in the codebehind file.
But it wasn’t until recently that I found that you don’t need to have access to an SMTP server to test your code.
In fact, this little trick will allow you to read the email without clogging up your email client with email you only wanted for testing purposes.
Instead of the normal entry of
<mailSettings> <smtp from="email@example.com"> <network host="maiServerl" password="password" userName="loginName" port="25"/> </smtp> </mailSettings>
You can use
<mailSettings> <smtp from="firstname.lastname@example.org" deliveryMethod="SpecifiedPickupDirectory"> <specifiedPickupDirectory pickupDirectoryLocation="c:\mail"/> </smtp> </mailSettings>
This will drop your email message in the c:\mail directory as an *.eml file which you can open with Outlook Express.
The code you would write to send the mail is still the same:
SmtpClient smtp = new SmtpClient(); MailAddress from = new MailAddress(fromEmail, fromEmail); MailAddress to = new MailAddress(emailAddress, emailAddress); MailMessage message = new MailMessage(from, to); message.Subject = SubjectLine; message.Body = htmlString; message.From = from; message.To.Add(to); message.IsBodyHtml = true; smtp.Send(message);
Like this Article? Subscribe to get every article sent to your email.
- Templated E-Mail using .NET One thing I’m pretty consistent about is letting the computer do most of my work for me. As a “programmer” I really don’t like to program. I prefer to solve problems. You’ve […]
- Managing Email I recently started using a product called Clear Context that does a much better job of integrating Outlook's email with Outlook's calendar. The two things I like best about it are that it […]
- Determine The Role of a User in ASP.NET There are several controls that allow you to display content based on the role a user is in, including: - LoginView - LoginStatus And the web.config file allows us to control which […]
- ASP.NET Session Variables Not Sticking I’ve stumbled across this problem twice in the last couple of months so I figure it is about time I blogged about it. The situation is that you have a page on your web site that […]
- Cross Language References in ASP.NET Most ASP.NET programmers are aware that the environment allows programmers to write code in multiple languages. This is what allows a programmer who prefers CSharp to write modules […]
- 18 August 2009 at 8:08am
- Dew Drop – August 18, 2009 | Alvin Ashcraft's Morning Dew
[...] Test Sending Email without a Server in ASP.NET (Dave M. Bush) ...