Category: Microsoft


In my last post, I promised to look at SendRawEmail next. I got busy on other projects so this has taken longer than I originally anticipated it would.

Converting MailMessage into a MemoryStream

public static MemoryStream ConvertMailMessageToMemoryStream(MailMessage message)
{
	Assembly assembly = typeof(SmtpClient).Assembly;

	Type mailWriterType = assembly.GetType("System.Net.Mail.MailWriter");

	MemoryStream fileStream = new MemoryStream();

	ConstructorInfo mailWriterContructor = mailWriterType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(Stream) }, null);

	object mailWriter = mailWriterContructor.Invoke(new object[] { fileStream });

	MethodInfo sendMethod = typeof(MailMessage).GetMethod("Send", BindingFlags.Instance | BindingFlags.NonPublic);

	sendMethod.Invoke(message, BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { mailWriter, true }, null);

	MethodInfo closeMethod = mailWriter.GetType().GetMethod("Close", BindingFlags.Instance | BindingFlags.NonPublic);

	closeMethod.Invoke(mailWriter, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { }, null);

	return fileStream;
}

When we create a request for the SES service, we need to give it a MemoryStream object that contains our mail message. I created a MailMessage object for this, but in order to give this to SES I had to convert it to a MemoryStream. I found the guts of the method above online, and slightly modified it for my own use. I’m not going to talk about it, but you can find it here.

SendRawEmail

public static Boolean SendRawEmail(String from, String to, String Subject, String text = null, String html = null, String replyTo = null, String returnPath = null)
{
	AlternateView plainView = AlternateView.CreateAlternateViewFromString(text, Encoding.UTF8, "text/plain");
	AlternateView htmlView = AlternateView.CreateAlternateViewFromString(html, Encoding.UTF8, "text/html");

	MailMessage mailMessage = new MailMessage();
	mailMessage.From = new MailAddress(from);

	List<String> toAddresses = to.Replace(", ", ",").Split(',').ToList();
	foreach (String toAddress in toAddresses)
	{
		mailMessage.To.Add(new MailAddress(toAddress));
	}

	//foreach (String ccAddress in ccAddresses)
	//{
	//    mailMessage.CC.Add(new MailAddress(ccAddress));
	//}

	//foreach (String bccAddress in bccAddresses)
	//{
	//    mailMessage.Bcc.Add(new MailAddress(bccAddress));
	//}

	mailMessage.Subject = Subject;
	mailMessage.SubjectEncoding = Encoding.UTF8;

	if (replyTo != null)
	{
		mailMessage.ReplyTo = new MailAddress(replyTo);
	}

	if (text != null)
	{
		mailMessage.AlternateViews.Add(plainView);
	}

	if (html != null)
	{
		mailMessage.AlternateViews.Add(htmlView);
	}

	RawMessage rawMessage = new RawMessage();

	using (MemoryStream memoryStream = ConvertMailMessageToMemoryStream(mailMessage))
	{
		rawMessage.WithData(memoryStream);
	}

	SendRawEmailRequest request = new SendRawEmailRequest();
	request.WithRawMessage(rawMessage);

	request.WithDestinations(toAddresses);
	request.WithSource(from);

	AmazonSimpleEmailService ses = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(AppConfig["AWSAccessKey"], AppConfig["AWSSecretKey"]);

	try
	{
		SendRawEmailResponse response = ses.SendRawEmail(request);

		SendRawEmailResult result = response.SendRawEmailResult;

		Console.WriteLine("Email sent.");
		Console.WriteLine(String.Format("Message ID: {0}", result.MessageId));

		return true;
	}
	catch (Exception ex)
	{
		Console.WriteLine(ex.Message);

		return false;
	}
}

The above method uses the .NET MailMessage class to create my email message.

Lines 3/4 create our alternative email messages so the email should be visible in whatever mail app is used to retrieve the emails.

Lines 9-13 add the TO addresses to the mail message. Again, I pass in the emails as a string separated by a semi-colon and convert this to a list. The mail message wants each address added as a MailAddress object so a foreach loop steps through the list and adds each address correctly.

Lines 15-23 do the same for CC and BCC address if you wanted to use them. I haven’t in my example, but include the code commented out for you. You’ll also need to add them so you can pass them in when calling the method (Line 1).

Line 25/26 sets the Subject and its encoding and then lines 28-41 add the Reply To address and our alternative views we created earlier (if the String isn’t null).

Line 43 creates our RawMessage object and then lines 45-48 call our method above to convert the MailMessage into a MemoryStream.

We create our request on line 50 and give it our RawMessage on line 51. We also give it our TO addresses and our FROM address on lines 53/54.

We connect to SES on line 56 and then get the response from giving SES our request on lines 60-62 and output to the console the Message ID and a confimation message on lines 64/65.

Other than converting the MailMessage to a MemoryStream this is pretty straight forward. I’ll do my best to help anyone having issues via the comments…

Neil

Smile

Until Windows Vista, it had been possible to install a clean copy of Windows without a previous version being installed. During the installation, it would ask you to insert the disk of the previous version and voila… it worked.

Microsoft changed things slightly with Vista (but I never actually upgraded so this didn’t affect me). With Windows 7 things are the same, except Paul Thurrott of the SuperSite for Windows website has a solution, with the help of some others. The solution can be found here:

http://community.winsupersite.com/blogs/paul/archive/2009/10/23/clean-install-windows-7-with-upgrade-media-the-answer.aspx

Thanks to Kevin Fisher and a bit of testing, I have a simple workaround that does work.

After performing the clean install, ensure that there are no Windows Updates pending that would require a system reboot. (You’ll see an orange shield icon next to Shutdown in the Start Menu if this is the case).

Then, open regedit.exe with Start Menu Search and navigate to:

HKLM/Software/Microsoft/Windows/CurrentVersion/Setup/OOBE/

Change MediaBootInstall from "1" to "0".

Open the Start Menu again and type cmd to display a shortcut to the Command Line utility. Right-click this shortcut and choose "Run as administrator." Handle the UAC prompt.

In the command line window, type: slmgr /rearm

Then tap ENTER, close the command line window and reboot. When Windows 7 reboots, run the Activate Windows utility, type in your product key and activate windows.

Voila!

Back in August I purchased a HP Mini 110 netbook PC. Since the initial release of netbooks, I had been a little hesitant about using one because of the size of the screen and the resolution that accompanied it. I decided to take the plunge anyway because it would be handy to have a small computer that I can carry around with me.

I had previously recommended the Samsung NC10 to friends, but at the time I was purchasing mine, this model had been replaced, and I got a very good deal on the HP and a Canon DSLR camera.

The HP came with Windows XP Home, and I was very pleased to find that the resolution could be increased to 1366 x 768. Some people may think this is too small for a screen size of 10.1 inches. I have found the screen a pleasure to use and not at all too small.

Although Windows XP is one of Microsoft’s better operating systems (and I liked Vista, it just had a few problems) I have become used to the look and feel of Windows 7 as I have be using it on my other machines since Microsoft made the Public Beta available. So I decided to take the plunge and install a clean copy of Windows 7 (the RTM version). A colleague of mine installed Windows 7 on his Asus Eee netbook, which, considering it has a SSD drive, took considerably longer than mine to install and failed to install the graphics drivers correctly, causing him a few headaches whilst he tried to find drivers that would work.

As netbooks don’t have in-built CD/DVD drives, I followed this guide to install Windows 7 from a USB stick. I only had a 2GB stick available to me so I used vLite to strip some un-needed files from the installation media before following that guide.

I wasn’t sure what to expect once the installation had fully completed, but I have found the experience of Windows 7 thus far to be very close to that of Windows XP. Ok, so it probably is a little slower, but not too different that I am considering a downgrade back to Windows XP. Not yet anyway…

I will post some more about my experiences as I use the Windows 7 packing netbook more and more.

We are getting close to releasing one of the projects at work. A website developed in ASP.NET using Visual Studio 2008.

With a project like this you need to test it in multiple web browsers to ensure that you cover all the bases when it comes to release time. The last thing you want is for the site to work in the specific version of a browser but not earlier versions of that browser or other browsers.

Testing in multiple browsers is easy enough, you just install them on your local development machine. However, testing a site in both IE7 and IE8 (for example) becomes more difficult. Even more so when you want to test on a Mac running OS X.

There are a number of immediate options that string to mind:

  1. You could develop against IE7 then upgrade to IE8 to fix any bugs.
  2. Develop against IE8 and downgrade to IE7 for testing and debugging (reverse of above).
  3. Test using VMs or remote client machines.

The first two options would be nice, but there are issues. Supposing the “fixes” break the site against the initial browser version you developed again. Add to that that the un-installation of IEx is not something I ever want to undertake after previous experience!

Option 3 sounds good, except that Microsoft have prevented you from accessing the ASP.NET Development Server from anything but localhost. Therefore you cannot browse to the site from any remote machine.

After some googling, I found the solution.

Visit the site for the complete lowdown, but for future reference by myself (and in case that site goes down at any time for any reason), here is a brief account.

  1. Download the Microsoft SOAP Toolkit from here.
  2. Install it.
  3. Start Microsoft SOAP Toolkit Version 3 > Trace Utility.
  4. Select File | Formatted Trace.
  5. You will be prompted for the port to listen on and the machine/port to forward to.
    • Local port # is the port the remote device will connect using.
    • Destination host should remain as localhost.
    • Destination port is the port number that ASP.NET Development Server is using.

If you now connect to the IP address or hostname of your development machine using the local port specified above, you should see the site you are developing against and can debug as usual.

Neil

Enable Remote Desktop

The steps involved in doing this are already discussed all over the Internet. As with most things I find the steps that work, bookmark them and then am unable to find the bookmark when I need it. So I post these steps for my own reference, but if this helps others do the same, that’s a bonus!

These steps can either be run locally, or remotely. To perform these steps remotely also carry out the optional steps, otherwise skip them and do it locally. :) .

Enable remote desktop in the remote registry.
  1. Run Regedit
  2. Select File | Connect Network Registry (Optional)
  3. Enter the name of the remote computer and select Check Names (Optional)
  4. Go to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\fDenyTSConnections
  5. Change the fDenyTSConnections to 0
Allow Remote Desktop through the Windows Firewall
  1. Get the PSTools from Microsoft. We need the psexec utility. (Optional)
  2. At a command prompt, run the following: psexec <remotecomputer> cmd (Optional)
  3. Run the following commands:netsh firewall set portopening protocol=TCP port=3389 name=TS mode=ENABLE profile=DOMAIN

    netsh firewall set service remoteadmin enable

    netsh firewall set service remotedesktop enable

Neil

In some previous posts (here and here) I blogged about having to use Lotus Notes at work and some of the things I didn’t like about the client.

Well today I had a go at installing Microsoft’s Outlook Connector for Domino. The connector can be downloaded from here: http://www.microsoft.com/DOWNLOADS/details.aspx?FamilyID=8ebbba59-5f17-4e52-8980-c4f0dfa92d65&displaylang=en

Having installed the connector, I loaded up Outlook and proceeded to add a new email account (Tools > E-mail Accounts > Add a new e-mail account > Additional Server Types > Microsoft Office Outlook Connector for IBM Lotus Domino). You must have the Lotus Notes client application installed and configured to use the connector, so the connector will automatically get the settings.

This didn’t work for me, giving me a message about the service not being able to start. As always with errors, I did a Google search and found many posts where people said that they went through uninstalling each update to Office 2003 since SP2 (note this connector is not designed for Office 2007).

This seemed long winded and should be my last resort.

Eventually I found another blog that told me to make sure the path to the Lotus Notes executable was in the PATH environment variable. On my system this was no longer there. So I added it (Right-click Computer > Properties > Advanced system settings > Environment Variables > Add it to System variables).

On my Vista system my path was C:\lotus\notes, which contained all the DLLs and the nlnotes.exe executable.

I then loaded Outlook again and it picked up my settings. Sorted!

I can’t open the Shared Calendar yet, but I’ll let you know when I have that working also!

Neil

A couple of days ago, I upgraded Windows Vista from SP1 to SP2. I left it running overnight and when I returned to my machine, all seemed well.

However, Windows Live Messenger refused to load. I restarted, but still nothing. No error message. Nothing.

So my first reaction, which also proved to be a fix, was to re-install Messenger. I didn’t un-install the version already installed, just re-ran the downloaded executable (you can get this from here).

Hope this works for you too!

Whenever I do a clean installation of Windows on my machines, its always a pain having to install the Service Packs for the relevant application separately from the application itself.

Thankfully, with some applications, its possible to slipstream, or integrate the latest Service Pack with the original files and build your self a new CD or ISO file.

Here’s how for Office 2007 Service Pack 2 (SP2):

1) Copy the contents of the Office 2007 installation media to a temporary folder, for this example: D:\Office2007.

2) Download the Office 2007 Service Pack 2 (SP2) from here:

Download details: The 2007 Microsoft Office Suite Service Pack 2 (SP2):
http://www.microsoft.com/downloads/details.aspx?FamilyID=b444bf18-79ea-46c6-8a81-9db49b4ab6e5&displaylang=en

3) Place the SP2 download in a temporary folder, for this example: D:\Office2007-Updates.

4) Open a Command Prompt and run the following command:

   D:\Office2007-Updates\office2007sp1-kb936982-fullfile-en-us.exe /extract:"D:\Office2007\Updates" 

5) Agree to the Microsoft Software License Terms, and then the update will be extracted to D:\Office2007\Updates.

6) Burn the folder D:\Office2007 to optical media (DVD) or create an ISO file.

Office 2007 will now install and then automatically install any updates.

I’m not a fan of the new “pin to taskbar” feature on Windows 7. I much prefer the old Quick Launch toolbar. If you are like me, you’ll be glad to know its quite easy to restore (or should I say recreate) this toolbar, and can be done following these steps:

  1. Right-click the taskbar and make sure that “Lock the Taskbar” is un-ticked.
  2. Right-click the taskbar again, hover over “Toolbars” and then click “New Toolbar”.
  3. Enter this folder path into the “Choose Folder” window that appears:

%userprofile%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch

On the right of the taskbar, you should now see a new toolbar called Quick Launch. All we need to do now is configure it so it looks like it did in previous versions of Windows:

  1. Right-click the divider for this toolbar and un-tick the “Show Text” and “Show Title” options (you may also need to ensure that the “Small Icons” option is selected.
  2. Drag the divider to arrange the new toolbar where you’d like it (I usually have it on the left just to the right of the start button).
  3. Right-click the taskbar and tick “Lock the Taskbar” again.

Applications should still be able to add their icons here as the path to the folder for this toolbar hasn’t moved. However, as new application are developed for Win7, I wouldn’t be surprised if they stop adding Quick Launch icons automatically. Still, its easy to add them yourself!!

Neil

Power Pack 2 for Windows Home Server has recently been released and whilst I’ve seen lots of news about what PP2 provides, I seem to have missed this one.

Power Pack 2 now adds the ability for the WHS console to correctly identify the OS of a PC running Windows 7.

whs_pp2_console

Previously it would have reported it as Windows Vista

Anyway, thought I’d mention it!

Follow

Get every new post delivered to your Inbox.