Sitemap of the Module Media Website

Home
Accessibility
Privacy statement
Sitemap
Terms of use
About Module Media
Our approach
Services we offer
User experience (UX)
Web standards & accessibility
Search engine optimization
Our Work
Select case studies
Complete client list
Training
About our training
Training on DVD
Published books
Current course offerings
Blog
Ideas, tips & tricks
Latest articles
Blog search
Tag cloud
Contact Module Media
Submit a question
Where we're located

Module Media | An innovative web design and application development firm with a passion for web standards

Our thoughts, ideas and rants.

Sending SMTP Email with Authentication using ASP.NET
Posted by Module Media on July 8, 2010

One of the topics I teach in my ASP.NET course is the process of sending email using SMTP. The process is relatively simple, you create a new instance of the MailMessage class, passing in two required parameters into the constructor: To and From email addresses. Next you set the Subject property, optionally set the IsBodyHtml property, and finally set the Body property with the content of your email that your recipients will actually read. To send the email you create a new instance of the SmtpClient class, passing in the path to the SMTP host and optionally set the port number. To send the email you simply call the Send() method, passing in the MailMessage object and you’re good to go. A generic implementation of this script begins to look something like this:

Dim oMail As New MailMessage("zak@modulemedia.com", "zak@modulemedia.com")
oMail.Subject = "CONTACT FORM"
oMail.IsBodyHtml = True
oMail.Body = "Message: " & txtMessage.Text

Dim oSend As New SmtpClient("localhost")
oSend.Send(oMail)


As you can see from this script, the code assumes that you’re using Localhost (127.0.0.1) as the SMTP mail server. This is fine if you’re using Windows 2000 or Windows XP Pro where the SMTP Virtual Mail server was still part of IIS. But what if you’re developing in Windows Vista or Windows 7 where SMTP Virtual Mail was eliminated for many reasons including security? What if you’re building an application that you’ll actually be deploying to a remote Web host and need to configure SMTP to use a mail server that requires authentication? Perhaps you want to use your Internet Service Provider’s (ISP) SMTP mail server for relaying email for the Web application you are building? In these scenarios, you’ll need to configure authentication in an effort to connect to your Exchange server or ISP’s mail server. This can be done easily in ASP.NET thanks to the NetworkCredential class. Accepting your username and password as parameters into the constructor, the NetworkCredential class assures authentication with your mail server. The above code can be modified accordingly as follows:

Dim oMail As New MailMessage("zak@modulemedia.com", "zak@modulemedia.com")
oMail.Subject = "CONTACT FORM"
oMail.IsBodyHtml = True
oMail.Body = "Message: " & txtMessage.Text

Dim oSend As New SmtpClient("mail.yourserver.com")
Dim oUser As New System.Net.NetworkCredential("admin@yourserver.com", "password")
oSend.UseDefaultCredentials = False
oSend.Credentials = oUser

oSend.Send(oMail)


As you can see we modify the parameter passed into the SmtpClient class to use the mail server that you want to authenticate to. Second, we create a new instance of the NetworkCredential class, passing in the username and password as parameters into the constructor. Next we set the important UseDefaultCredentials property to False. By default, this property is set to True which means anonymous credentials are passed to the mail server…this is usually why you’ll receive an error message in regards to authenticating to the mail server. Setting this property to False guarantees that our username and password are passed in instead. Finally we set the Credentials property of our SmtpClient object variable equal to our NetworkCredential object variable, call the Send method, and we’re done. Email should send successfully!

Comments: 0     Tags: ,
Module Media, one of Top 10 Sites for Designers by How Design
Posted by Module Media on December 1, 2009

How Design Magazine has just selected Module Media as one of their top 10 websites for designers for the month of Decemeber. Christmas came early for us this year. Check out How Design website while you're there, they have a ton of creative resources including blogs, forums, regularly posted articles, and more.

Comments: 0     Tags: ,
Reading the syndication.axd file from your BlogEngine.NET powered blog
Posted by Module Media on November 5, 2009

If you’re reading this blog entry, chances are you’re unaware (and probably don’t care) of how it was built. The questions don’t start popping up until it’s time for you to create your own blog and when that time comes, you’ll have tons of options to choose from. The one I use, primarily because of my fondness of ASP.NET, is BlogEngine.NET. BlogEngine.NET, like most blogging applications is free to download, easy to install and customize, and more importantly offers just about all of the same options as some of the other popular blogging applications built using competing technologies like PHP. My purpose of this entry is not to compare blogging applications, but to present a solution to a dilemma that I had while attempting to integrate BlogEngine.NET with the Module Media site redesign. That is, how do I take my latest blog entries and make them available directly within the front page of my web site so that the user can go directly to the front page of my web site and see whether a new blog entry exists. And if one does, allow them to directly link to that new blog entry. The answer to this problem wasn’t as simple as I had imagined it would be. In the end, I had to resurrect my XSL skills and put my XML and VB.NET skills to the test to get the job done. Let’s take a look.

BlogEngine.NET, like all blogging applications generates a file that is used to syndicate blog entries via RSS, called syndication.axd. This file, which is generated at the root of your blog, can be read in my any feed reader application, including your browser, simply by “subscribing” to it. For instance, if you browse to mine http://www.modulemedia.com/blog/syndication.axd, you’ll see the RSS feed for the Module Media blog. Pretty straight forward right? The question I had was how do I take the top 5 headlines, including their dates from this syndication file and make them available as the latest entries on the main page of the Module Media site? To add to this dilemma, I also wanted to make it so that each entry linked back directly to the blog posting. Since most of the work is done by the syndication.axd file, reading it is simply a matter of writing a XSL file to “transform” the data in the XML-based syndication.axd file into something meaningful that our web page index.aspx can use and ultimately display. I started off with a XSL file in a scripts folder on my site called rssTransform.xsl. Here’s what it looks like:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="html" />
     <xsl:template match="/">

     <ul id="lbptext">
          <xsl:for-each select="rss/channel/item[position() &lt; 5]">
               <li>
                    <span>
                         <xsl:call-template name="getDate">
                              <xsl:with-param name="dateTime" select="pubDate" />
                         </xsl:call-template>
                    </span>
                    <xsl:element name="a">
                         <xsl:attribute name="href">
                              <xsl:value-of select="link" />
                         </xsl:attribute>
                         <xsl:value-of select="title" />
                    </xsl:element>
               </li>
          </xsl:for-each>
     </ul>
</xsl:template>

<xsl:template name="getDate">
     <xsl:param name="dateTime" />
     <xsl:value-of select="substring($dateTime,9,4)" />
     <xsl:value-of select="substring($dateTime,6,2)" />,
     <xsl:value-of select="substring($dateTime,13,5)" />
</xsl:template>
</xsl:stylesheet>

To make a long and complex file short, the XSL file’s primary responsibility is to take XML data (syndication.axd) and transform it into something that is a bit more meaningful to a browser (HTML). If you look at the file closely, you’ll see actual HTML tags combined with XSL tags. For instance, the portion of code that does the majority of the work is the for-each loop. Essentially what we’re doing is looping through each item in the syndication.axd file. We do this operation five times to read in the top 5 entries. We then display the date (which is formatted by calling a function called getDate written out near the bottom of the page) and a hyperlinked version of the title within a HTML <li> tag. Of course this is possible because all syndication files outline names for each of their entries. Each entry is called “item”, each item has a “title”. Each entry also has a “link” and published “dateTime” amongst others.

With the data now being transformed into something meaningful, it’s now time to associate the XSL file to the syndication.axd (XML) file and more importantly display the data within a the page. This is done using VB.NET on the main page of our web site index.aspx as follows:

<script language="VB" runat="server">              
     Sub Page_Load(sender As Object, e As EventArgs)
          Dim strXmlSrc As String = "http://www.modulemedia.com/blog/syndication.axd"
          Dim strXslFile As String = Server.MapPath("scripts/rssTransform.xsl")

          Dim myXmlDoc As New XmlDocument()
          myXmlDoc.Load(strXmlSrc)

          Dim myXslDoc As New XslCompiledTransform()
          myXslDoc.Load(strXslFile)

          Dim myStringBuilder As StringBuilder = New StringBuilder()
          Dim myStringWriter As StringWriter = New StringWriter(myStringBuilder)

          myXslDoc.Transform(myXmlDoc, Nothing, myStringWriter)
          litModuleMediaRSS.Text = myStringBuilder.ToString()
     End Sub
</script>

In order of operation, we read in both syndication.axd and rssTransform.xsl files and set them to string variables called strXmlSrc and strXslFile respectively. We then create a new instance of the XmlDocument() c lass. This gives us access to the Load() method which we use to load up our XML (syndication.axd) file by passing in the strXmlSrc variable as a parameter into the method. We do the same for the XSL file, creating a new instance of the XslCompiledTransform() class and then passing in the strXslFile variable as a parameter into the Load() method of this class.

Next we create new instances of the StringBuilder() and StringWriter() classes, used to format and output programmatically constructed strings. We then call the Transform() method of myXslDoc object variable, passing in the XML document, represented by the myXmlDoc object variable and the instance of the string writer object, myStringWriter. Finally, we set the Text property of a Literal control that I have on the page equal to the string builder object. The final result is formatted using CSS to appear like what you see on the main page of the Module Media site.

I've attached a working version of these files to this entry titled mm_readingrssfiles.zip. Have fun!

Comments: 0     Tags: , , , ,
10 Harsh Truths About Corporate Websites
Posted by Module Media on July 15, 2009

I honestly don't know where to begin here. Every single point made in this article is so dead on that I found myself having to share it on my site. In my 15 years of working independently and in the private and public sectors, I found myself drawing examples for every point made from my previous experiences. The point I found particularly interesting was point 1, "Managing your Website is a Fulltime Job."

I can't tell you how many sites I've inherited from clients who thought they'd "give it a shot." I tried fixing my car once...keyword here being once. Designing your web presence...your message between you and your customers should be left up to a skilled person who does this kind of work for a living, much like the mechanic does for your car. Trained professionals know good web design which brings usability, user experience, accessibility, etc. Skilled web programmers know when an out-of-the-box CMS will do, when a custom CMS is needed, or when one isn't required at all. SEO specialists will understand search engine optimization, when to rely on social networking (see point 7), when to pay for ad-clicks, or when to go completely organic. If I had a nickel for every student who came to me and asked me for help after their Marketing Director or VP of Engineering made them take my classes only to find that they were in above their heads, I'd be a rich man.

Comments: 0     Tags:
MySpace lays off 30 percent of its workforce
Posted by Module Media on June 17, 2009

Is this a big surprise? With the advent and virtual takeover from social networking sites like Facebook, Twitter, etc., the once giant MySpace is once again trimming the fat. I'm not surprised to be honest, MySpace remains a giant in the social networking community but a site I've avoided for personal use like the plague. Why? Web standards and companies actively pushing for Web 2.0 technologies have been on the rise. People are beginning to genuinely understand why web standards, accessibility, user experience, etc., are so important. Shoot even Microsoft is making strides with IE 7 and IE 8. For the past 5 years the web has really taken two giant steps forward while MySpace and their lame CSS "code" injection techniques seem to want to take three steps back. Gotta love the black backgrounds with dark navy blue text and a web site whose architecture is fragmented between ColdFusion and ASP.NET.

Comments: 0     Tags:
We have a blog, it's about time...
Posted by Module Media on June 14, 2009

Well folks it's been a long time coming but I'm happy to announce that Module Media finally has a blog. With the launch of the new website, we felt it important to also include a blog so that all of our current and former students, clients, and customers can keep in the loop with what we're doing. We have so many ideas, tutorials, tips, tricks, reviews, and general rants that we want to share with everyone. With that said, please feel free to subscribe to our RSS feed so that you can stay in touch. Thanks to everyone for your continued support - stay tuned.

Comments: 0     Tags:
Welcome to BlogEngine.NET 1.5.0
Posted by Module Media on April 2, 2009

If you see this post it means that BlogEngine.NET 1.5.0 is running and the hard part of creating your own blog is done. There is only a few things left to do.

Write Permissions

To be able to log in to the blog and writing posts, you need to enable write permissions on the App_Data folder. If you’re blog is hosted at a hosting provider, you can either log into your account’s admin page or call the support. You need write permissions on the App_Data folder because all posts, comments, and blog attachments are saved as XML files and placed in the App_Data folder. 

If you wish to use a database to to store your blog data, we still encourage you to enable this write access for an images you may wish to store for your blog posts.  If you are interested in using Microsoft SQL Server, MySQL, VistaDB, or other databases, please see the BlogEngine wiki to get started.

Security

When you've got write permissions to the App_Data folder, you need to change the username and password. Find the sign-in link located either at the bottom or top of the page depending on your current theme and click it. Now enter "admin" in both the username and password fields and click the button. You will now see an admin menu appear. It has a link to the "Users" admin page. From there you can change the username and password.  Passwords are hashed by default so if you lose your password, please see the BlogEngine wiki for information on recovery.

Configuration and Profile

Now that you have your blog secured, take a look through the settings and give your new blog a title.  BlogEngine.NET 1.4 is set up to take full advantage of of many semantic formats and technologies such as FOAF, SIOC and APML. It means that the content stored in your BlogEngine.NET installation will be fully portable and auto-discoverable.  Be sure to fill in your author profile to take better advantage of this.

Themes and Widgets

One last thing to consider is customizing the look of your blog.  We have a few themes available right out of the box including two fully setup to use our new widget framework.  The widget framework allows drop and drag placement on your side bar as well as editing and configuration right in the widget while you are logged in.  Be sure to check out our home page for more theme choices and downloadable widgets to add to your blog.

On the web

You can find BlogEngine.NET on the official website. Here you'll find tutorials, documentation, tips and tricks and much more. The ongoing development of BlogEngine.NET can be followed at CodePlex where the daily builds will be published for anyone to download.

Good luck and happy writing.

The BlogEngine.NET team

Comments: 0     Tags: ,