Archive for February, 2009

Email Fun

February 27, 2009

In speaking with a co-worker, I mentioned a couple email tips that he hadn’t heard. Thinking that others may be in the same boat, I offer them here:

  • Gmail: you can put periods throughout the username and Google will ignore them. So “bbrown” can be “b.brown,” “bbr.own,” or even “b.b.r.o.w.n.” and the emails will come through.
  • Gmail: you can append a plus sign and additional text to the username and Google will also ignore that text. “bbrown+specialdeal,” “bbrown+spam,” and “bbrown+yahoo” all get to their proper final destination. This and the other tip plus Gmail’s filters enable you to create disposable email addresses without preplanning.
  • Mailinator is the king of throwaway email addresses. In a form, enter and you can access that username’s messages through the mailinator Web site. Anyone else can access the email, so this isn’t really useful for anything besides anonymous emailing. Some sites have caught on and check for the mailinator domain name, but there are plenty of aliases available (you can even point your own domain’s MX record there).

WebException and the HttpWebResponse

February 21, 2009

The following code is used to make a request and get the results:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("");
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(resp.GetResponseStream());
string contents = reader.ReadToEnd();

contents will contain the HTML of this blog if the server gives a 200 OK response. Anything else will throw a WebException. You can wrap the snippet above in a try-catch to handle a non-200, but the exception is thrown in the GetResponse call so you get nothing from the actual response. 404? May as well be a 500.

Today I discovered that the WebException itself has two properties: Response and Status. This Response is the same as the resp above so you can extract out the server response in the catch.

This whole behavior of HttpWebRequest is counterintuitive in the sense that a non-200 is not an exceptional circumstance; I would have expected the response to be accessible and the status code to be populated.