This article contains few funny things which I would like to share with you guys. Well, we will discuss about how we can add random quotes in our email signature. Please note that we will use Microsoft Office Outlook 2007 as our email client software.
I love quotes especially inspiration or motivational quotes & I really enjoy using quotes in my email signature. When I'm trying to choose quotes for my email signature, I am stuck! Which one should I take, there are a large number of quotes are available and I could not choose one of them. Finally, I decided that I will write a program which will randomly add quotes in my Outlook email signature.
So let’s start from the very beginning. When I started writing this program, I was a little bit confused because I could not decide which one I would use, should I go for Add-In or Windows services or a simple Win32 Form application. So finally I decided that I will go for Win32 application.
How To Do That
I use very basic techniques / ways to do this. They are listed below:
- Create a signature in Microsoft Office Outlook.
- Add a key word (#quotes#) at the bottom of the signature.
- Create a template of the current signature.
- Create an XML document that contains all the quotes.
- Finally add the quotes when Outlook is running.
Let’s discuss it with more detail and go through the list above.
Create a Signature in Microsoft Office Outlook
Well at first, we will create a signature file; it’s very simple. Just open / run Microsoft Office Outlook and select “Option” from the tools menu. A single Windows Form will appear with multiple tabs ? select “Mail Format” tab. You will find a button called “Signatures…”, under this tab click on the button and create your Outlook email signature.
Add a Keyword (#quotes#) at the Bottom of the Signature
Great! You create your signature and now add the key word (“quotes”) at the bottom of your signature. The following figure-A shows the key word with a signature.
Figure-A shows the key word with a signature.
Create a Template of the Current Signature
Now we will create the template of the current signature. We will use this template for randomly selected quotes and update the Microsoft Office Outlook signature file. Note that I face a lot of issues when I update the Outlook signature file, for example text encoding, getting garbage manipulating the string, etc. I would appreciate your idea to resolve this in a good manner. Actually the current code is a little bit sloppy (my personal opinion). Anyway a sample code snippet is given below for the current scenario.
public void SignatureRawText(int index, bool isStart)
applicationDataDir = Environment.GetFolderPath
(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Signatures";
signature = string.Empty;
DirectoryInfo diInfo = new DirectoryInfo(applicationDataDir);
FileInfo fiSignature = diInfo.GetFiles("*.htm");
if (fiSignature.Length > 0)
applicationDir = Environment.CurrentDirectory;
fileName = fiSignature.Name.Replace
if (File.Exists(applicationDir + @"\template.htm"))
diInfo = null;
diInfo = new DirectoryInfo(applicationDir);
fiSignature = diInfo.GetFiles("*.htm");
StreamReader streamReader =
new StreamReader(fiSignature.FullName, Encoding.Default);
signature = streamReader.ReadToEnd();
File.Copy(fiSignature.FullName, applicationDir + "/template.htm");
QuotesService32.Class.IQuotesSignature quotesSignature =
string strQuotes = Environment.NewLine
+ "<p style="
+ "font-family: Arial, Helvetica, sans-serif;
font-size: 10px; font-weight: normal;
color: #008000; text-shadow: 2px 2px 8px #444"
signatureText = signature.Replace("#quotes#", strQuotes);
signatureText = signature.Replace("#quotes#", "")
byte seeds = System.Text.Encoding.ASCII.GetBytes(signatureText);
FileStream fileStream = new FileStream(applicationDataDir + "/" +
fileName + ".htm", FileMode.Open,
BinaryWriter binaryWriter = new BinaryWriter(fileStream);
for (int i = 0; i < seeds.Length; i++)
if ((seeds[i]) != Convert.ToByte('?'))
catch (Exception exception)
A function to check whether your Office Outlook is running or not:
public bool IsOutlook7Running()
bool retVal = false;
foreach (Process availableProcess in Process.GetProcesses("."))
if (availableProcess.MainWindowTitle.Length > 0)
if (availableProcess.ProcessName == "OUTLOOK")
catch (Exception exception)
retVal = false;
Create an XML Document that Contains all the Quotes
We will create a very simple XML file which will contain all the quotes with an ID. I use x-path for retrieving quotes from the XML document. A simple XML template is given below:
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2011-11-26T15:32:29">
<tx_quotes>"What lies behind us and what lies before us are tiny matters
compared to what lies within us." - Ralph Waldo Emerson</tx_quotes>
<tx_quotes>"God, grant me the serenity to accept the things I cannot change,
the courage to change the things I can, and the wisdom to know the difference."
- Reinhold Niebuhr</tx_quotes>
<tx_quotes>"Honesty is the first chapter in the book of wisdom."
- Author Unknown</tx_quotes>
A sample code snippets for retrieving the quote from the XML document is as given below:
public string GetQuotes(int index)
string Quotes = string.Empty;
applicationDir = Environment.CurrentDirectory;
xPathDocument = new XPathDocument(applicationDir +
xPathNavigator = xPathDocument.CreateNavigator();
strExpression = "/dataroot/T_QUOTES_TEXT
[./id_quotes_key=" + Convert.ToString(index) + "]";
xPathNodeIterator = xPathNavigator.Select(strExpression);
Quotes += xPathNodeIterator.Current.Value;
Quotes = string.Empty;
For more about x-path, you can click on this link.
Finally Add the Quotes when Outlook is Running
Well, we are almost done! Now we will create a simple Windows application which will be run and display as system tray application with the following menu:
Figure-B shows the quotes addition and figure-C show the running state of this program:
Figure-B shows the output / randomly selected quote in your email signature.
Figure-C showing the application running state.
Points of Interest
Few more things I would do is make it generic, XML data manipulation and some more features.
I hope you guys get the scenario. So if you want to use quotes in your Outlook email signature, now you can create your own application.
- Tuesday, November 29, 2011: Initial post
He is the founder & CEO of MNH Technologies and working for urban and rural sectors to improve people’s lifestyle, better medical facilities, education, social business etc. He has over ten years of professional experiences in design and developing Client-Server, Multi-Tier, Database, Web based business software solutions, Enterprise Applications, API, WebAPI, Google Analytics implementation, Add-In, Documentation & Technical Writing etc for Windows / Mac using Microsoft SQL Server, Oracle, MySql, PS, C#, VB.NET, ASP.NET, PHP, RoR, Visual Basic etc. He has also more than two years experience in Mobile-VAS (Platform Development).
He worked for various software development & technology consulting. His core focus on technologies to create dynamic data-driven systems that add value to your business and dynamic technology consulting that builds advanced solutions for the industries across the various vertices.
He also work as a Solution Architect at Dhrupadi Techno Consortium Limited (DTCL) and responsible for analyzing business requirements and offered optimum solutions (multiple options), which would address all current requirements, provide flexibility for future growth and allow smooth transition between old system and new system.
He graduated with honors from The University of Asia Pacific, in Computer Science and Engineering. He was awarded as “Most Valuable Professional” (MVP) at 2010 and 2011 by CodeProject.com and also selected as a Mentor of CodeProject.com
Specialties: Software Development Management, System Integration, Data Warehouse Architecture, Virtualization.