Wanta .NET ?

Dave Wanta

July 2003 - Posts

Demeanor Just Rocks

I just have to blog about the AWESOME obfuscator Demeanor. I ran into a problem today while testing an upcoming version of aspNetEmail.  It seemed that when I obfuscated aspNetEmail with Demeanor, the obfuscated version was throwing an exception that the non-obfuscated version wasn’t. So I quickly fired off an email to Brent at Wiseowl explaining my dilemma. Within 10 minutes I had an updated version of Demeanor in my inbox and I was back in business!!!. Not only did he provide me with a solution, he gave me some additional tips and tricks for better obfuscation. He just ROCKS when it comes to customer service. 

Cheers!
Dave

123aspx.com has RSS

Well, I finally exposed the latest resources on www.123aspx.com as a RSS feed. If you want to stay up-to-date with all the latest and greatest articles, tutorials, and products, you can subscribe to the feed here.

Cheers!
Dave

kbAlertz has RSS Feeds -- Finally!

If you haven’t heard of kbAlertz, it’s a website I setup to email me (and other subscribers) when Microsoft publishes new KB articles for their technologies.

I’ve finally gotten around to exposing the Kbs as a RSS feed. Basically, pick the technology you want to subscribe to, and I’ll expose the latest 10 Microsoft Knowledge base articles as a RSS feed.

You can pick from the list of technologies here.

This is my first attempt at RSS feeds, so if I’ve buggered something up, let me know.

Cheers!
Dave

System.Web.Mail Explained - Part 2

Introduction
Ok,  in my last blog entry you’ve seen how SMTP works. This article will delve into System.Web.Mail to see how it was built.

I’m sure when Microsoft was building the CLR framework they had many thousands of priorities on what to build first, and how to build it. Many of the namespaces and classes in the CLR framework are simply wrappers around some of the legacy COM components. System.Web.Mail is one of those namespaces.

CDOSYS and CDONTS
System.Web.Mail is unique when it is a wrapper round the COM components, because it is actually a wrapper around two COM components, CDOSYS and CDONTS. Internally, System.Web.Mail will check what the operating system it is being executed on, and then all the respective COM component. This makes troubleshooting interesting, because moving System.Web.Mail code from OS to OS can cause different exceptions to occur.

Using Anakrino, let’s look internally at what System.Web.Mail is doing.
In this first screen shot, I’ve expanded the System.Web.Mail.SmtpMail class to see some internal classes called CdoNtsHelper and CdoSysHelper.




These classes merely wrap CDONTS.NewMail and CDO.Message respectively. In fact, here is what their cctor()'s code looks like

[ CdoNtsHelper ]
private static CdoNtsHelper() {
 CdoNtsHelper._helper = new LateBoundAccessHelper("CDONTS.NewMail");
}

[ CdoSysHelper ]
private static CdoSysHelper() {
 CdoSysHelper._helper = new LateBoundAccessHelper("CDO.Message");
}

Ok, so now that we see System.Web.Mail is a COM wrapper, lets look at how System.Web.Mail.SmtpServer.Send() determines what class to call. Internally, the Send() method looks like

[ SmtpServer.Send() ]
public static void Send(MailMessage message) {
 if (Environment.OSVersion.Platform != 2)
  throw new PlatformNotSupportedException(SR.GetString("RequiresNT"));
 if (Environment.OSVersion.Version.Major <= 4) {
  CdoNtsHelper.Send(message);
  return;
 }
 CdoSysHelper.Send(message);
}

From this code we can see that System.Web.Mail requires NT. It also checks to see if NT is version 4.0 or less. If so, it will use the CDONTS.NewMail object. If the OS is greater than 4.0, it uses the  CDO.Message object. 

So now that we know how System.Web.Mail was built, it makes troubleshooting ‘easier’. We also begin to realize some of the limitations of System.Web.Mail, and realize that it can’t outgrow the limitation of the CDONTS.NewMail or CDO.Message object.

What's Next?
In the next blog entry, I hope to discuss some of common exceptions thrown by System.Web.Mail and how we can troubleshoot them.

Questions? Comments? What do you think?

 

System.Web.Mail Explained

System.Web.Mail and SMTP Explained

Building aspNetEmail, aspNetMime, and aspNetMX, has caused me to debug quite a few different email scenarios, for both client and friends.  Over the next few blog entries, I’m going to explore SMTP and System.Web.Mail to explain what is happening.

Lets first start with SMTP. SMTP (Simple Mail Transfer Protocol ) was first introduced around 1982 with RFC 821. Its now been updated to RFC 2821. SMTP is *ONLY* used for sending email. It is not used for retrieving email from the server, or managing email, or parsing it. Its only used for client to server, or server to server communication.  SMTP is totally text based. Which means, if we want to troubleshoot a SMTP session, its as easy as opening a Telnet session to a mail server and issuing commands.

SMTP Commands
Speaking of commands, lets talk about a couple of them. HELO, MAIL FROM, RCPT TO, DATA, RSET, QUIT. These commands are issued during a SMTP Session. The also need to be issued in a certain order.

Each of these commands take a line of text (with the exception of DATA), and are executed with a Carriage Return Line Feed Combination.

DATA is actually executed with a Carriage Return Line Feed . Carriage Return Line Feed combination
[VB]
vbCrLf + "." + vbCrLf
[C#]
"\r\n.\r\n"

After each of these commands are executed, the server will reply with a 3 digit reply, followed by a textual description. From server to server, this description may be different, but the command has to be the same. For a detailed look at the possible replies, check out RFC 2821.

HELO, MAIL FROM, RCPT TO, RSET, QUIT Commands

HELO
HELO is merely used to say "hello" to the server and introduce yourself. And example of the command is
HELO davesLaptop

Here I basically told the mailserver who I was.

MAIL FROM
The next command, in the SMTP session is the MAIL FROM command. This command will tell the server who the mail is from. Its issued like
MAIL FROM: <
dave@aspNetEmail.com>

RCPT TO
The next command, is the RCPT TO command. It tells who the mail will be going too. For example:
RCPT TO: <
you@yourcompany.com>
RCPT TO: <
him@hiscompany.com>
RCPT TO: <
her@hercompany.com>

As you can see, there were multiple RCPT TO commands issued here.  A RCPT TO command must be issued for everyone listed on your ‘TO’, ‘CC’ and ‘BCC’ line of the email.

DATA
The next command issued is DATA, which will actually send the text content of the email. The text content includes all of the email headers and the body.  Because the content contains multiple lines, the DATA command is terminated with a CrLf.CrLf sequence. For example:

DATA
This is my text email. It will
contain
a
few
lines of data


.

(notice the period at the end, on a line by itself? That’s how the DATA command was terminted).

RSET and QUIT
The last two commands that can be issued anytime during the SMTP session are the RSET and QUIT commands. They are executed on a line by themselves. RSET resets the SMTP session back to its original state, and clears any previously issued commands. QUIT gracefully closes the SMTP session.

To see this in action, here is a screen shot of a telnet session between me and my SMTP server.

 

Conclusion
In this blog entry, I’ve explained some of the SMTP commands used during a SMTP session. In the next blog entry, I’ll delve more into the System.Web.Mail namespace.


 

Google Dance Syndrome

You’ve used google before, but did you know they keep copies of their index around the world? And when the index is being updated, you can search on the same phrase at different times, and get different results. If you would like to see how that phrase looks across all clusters of their indexes, check out http://www.google-dance.com/ .

Cheers!
Dave Wanta

So you've decided build a Newsletter, huh?

Building a Newsletter

Building some of the most popular .NET email components (aspNetEmail, aspNetMime, aspNetPOP3 ) has taught me a lot about email publishing. I thought I would share some tips with you about building a newsletter.

So you’ve got a site up and running, or you have an online business. Do you have a newsletter yet? If not, why not? Email is the life blood of the internet (will it soon be replaced by RSS?)  If you have a website, evidently you have content or a product that you want people to be interested in. And if they are interested in it, maybe they want to get notified when there is new information or a product upgrade available. I subscribe to at least 10 different newsletters, because I want to be proactively notified about new things.

In fact, newsletters can become a huge avenue of people staying up-to-date with your content. For example, my newsletters at www.123aspx.com or my www.kbAlertz.com daily newsletters. I probably do just as much traffic through my newsletters (if not more), than I do through the actual web pages.

TEXT or HTML?

So, you’ve decided to publish a newsletter, what should it be TEXT or HTML?  Well, I can tell you what people tell me they like, and then I can show you the stats. The die hard TEXT only guys seem to be pretty outspoken, they claim that’s the only type of newsletter they like to see. That’s fine, but according to my stats on www.123aspx.com and www.kbalertz.com I do about 10x more HTML newsletters than TEXT newsletters. So I’d have to recommend you have a HTML newsletter, minimum,  no questions asked. However, if at all possible, you need both. Why alienate 10% of your audience if you don’t have too?  The only difference in recording the type of subscription should be a bit field in the database.  Designing the letter may be a little more tricky, but again, its worth that 10%.  Especially if you’re like me, sending out over a 1/4 million newsletters a week (Yes, they are opt-in, not spam).

So what client do you design for?

Well, unlike the browser, there isn’t any way to tell what type of reader your client is using to read that newsletter, so you have to go based upon surveys. Let me just say that Outlook and Outlook express rule this market, with Yahoo Mail and Hotmail close on their heels. Designing a safe newsletter for either of these clients should keep you covered nicely. But how much does MS actually control the email client market? Well, here are the results from a study I revisit from time to time:

The study is a little old, but you can view it here. The numbers may change, but I believe the trend stays the same, at least for now.

 

Q. Which of the following email clients/accounts do you primarily use for work-related email?
Email/Client Adjusted Percentage
AOL 7.0 4.92
AOL 6.0 0.61
AOL 5.0 0.61
AOL 4.0 or lower 0
Microsoft Outlook 39.14
Microsoft Outlook Express 25.20
Eudora 4.30
Netscape 5.33
Hotmail 25.82
Yahoo! Mail 19.67
Lotus Notes 6.35
UNIX Command-Line Based 1.43
Juno 0.61
Other (write-in optional) 19.06


Q. Which of the following email clients/accounts do you primarily use for personal email?
Email/Client Adjusted Percentage
AOL 7.0 6.52
AOL 6.0 0.81
AOL 5.0 0.81
AOL 4.0 or lower .20
Microsoft Outlook 24.03
Microsoft Outlook Express 27.70
Eudora 3.67
Netscape 5.30
Hotmail 33.20
Yahoo! Mail 27.29
Lotus Notes 0.41
UNIX Command-Line Based 1.22
Juno 0.81
Other (write-in optional) 16.29

 

Are you capable of receiving HTML as well as text email formats?
Response Adjusted Percentage
Yes, I can receive both HTML and text. 89.18
No, I can not receive HTML-formatted email. 2.65
Don't know/not sure 8.16
Total 100.00

Questions? Comments? Got any gripes about a newsletter you subscribe to? Or would like to see done differently? What email client do you use?

Securing Site Content/Images

Lets face it, its pretty difficult to secure site content and/or images on the internet. If it can be accessed via the web, it can probably be automated in someway to retrieve/download it.

A year or so ago, someone was telling me, the way they secure some image data, for their gallery, was to check the Http Referer, and if it matches their site, they let the images through.

This is great, however, the Http Referer is actually sent from the browser, so this technique depends upon two things:
a. The browser sends the correct Http Referer (which I’ve seen bugs with this).
and
b. Someone doesn’t spoof the Referer.

And with .NET this has even gotten easier, in fact, I whipped up a console app and was able to generate this code.

Imports System.IO
Imports System.Net
Imports System.Net.WebRequest

Module Module1

    Sub Main()

        Console.WriteLine(FetchURL("http://www.google.com"))

        Console.ReadLine()

    End Sub


    Function FetchURL(ByVal SomeURL As String) As String
        Dim WebResp As HTTPWebresponse
        Dim HTTPGetRequest As HttpWebRequest
        Dim sr As StreamReader
        Dim myString As String

        HTTPGetRequest = WebRequest.Create(SomeURL)
        HTTPGetRequest.KeepAlive = False
        HTTPGetRequest.Referer = "http://www.microsoft.com"
        WebResp = HTTPGetRequest.GetResponse()
        sr = New StreamReader(WebResp.GetResponseStream(), System.Text.Encoding.Default)
        myString = sr.ReadToEnd()

        Return myString

    End Function

End Module


Cheers!
Dave

The tools I like to use

A number of people have pestered me about blogging, so here I go. I don’t know how often I’ll blog, but I guess well see.

Just a smidge about me, if you don’t recognize my name, I’ve written www.123aspx.com and www.kbAlertz.com , and I’m also an INETA speaker. I actually just spoke at the Boulder .NET usergroup, where I got to meet Joe from ORM. Super nice guy. If you need a data modeling/code generation tool, you need to check these guys out.

Well, I was trying to figure what I wanted to blog about, and I got to thinking about all of my INETA presentations. All of them eventually turn to the tools and resources I use to help me write code. So I thought I would share some of them with you here.

Tools I Like to use:

Anikrino
This is a must have for any developer. If you don’t have this tool in your arsenal, then set that browser process on "HIGH" and scream over and grab this gem. If you’ve ever wanted to see how the framework was built, then this is the tool to do that.

Demeanor
Demeanor stops people from using Anikrino on your code. Yes, there are cheaper obfuscators, but I must say Brent has done a superb job with it, and it simply rocks. Worth it for any serious developer who needs to publish production code.

Rotor Source Code
When Anikrino isn’t working properly then I try and go to the source. Rotor Source. Last year some time I found myself going over and over the source code, but I wished I had a browser for it. So I wrote a web based interface that categorizes rotor’s namespaces and classes.

Alex Lowe’s Super Duper C# Translator
Have you ever wanted to know what that C# code looks like in VB? Well, then this is the code to do that. Since I write in C#, my VB is pretty rusty. But when someone asks me for a VB code snippet, I’ll just pull up this page, enter the code in the TEXTAREA, and translate. Need to check this out.
BTW, Alex, if you read this, when are you going to add a "Email this code to someone" button on that page?

Reflector
If you like Anikrino, then you may also like Reflector. Lutz has incorporated a decompiler in his browser tool, and it decompiles down to C# or VB. (Anikrio only does C#)

ILDASM
When Reflector and Anikrino don’t work, and it’s not listed in rotor, then it’s time to look at some good ‘ol IL. ILDASM to the rescue.

Resources that Keep me up to date
I subscribe to tons of newsletters. If I had to subscribe to any two that would keep me up to date they would be:

www.123aspx.com Daily Newsletter
This is my little newsletter that I try to publish every day. It contains all the new resources I just added to 123aspx.com. It keeps you on top of the new products, tutorials, applications and resources you might be missing. Yes, it’s a plug for myself, but if you really want something new in your inbox every day, you need to subscribe.

www.dotnetwire.com
.NET Wire is the only other .NET newsletter I like. It seems to catch some of those resources I end up missing.


These are the basic tools I use. There are a few others but these are the main ones that I use just about anytime I’m coding.

Am I missing any? Lets hear ‘em. C’mon, share with the rest of us.

Cheers!
Dave

More Posts