Click here to Skip to main content
13,356,318 members (58,874 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 29 Nov 2011

Add Random Quotes in your Outlook Email Signature

, 29 Nov 2011
Rate this:
Please Sign up or sign in to vote.
Add random quotes in your Outlook email signature


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:

  1. Create a signature in Microsoft Office Outlook.
  2. Add a key word (#quotes#) at the bottom of the signature.
  3. Create a template of the current signature.
  4. Create an XML document that contains all the quotes.
  5. 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);
    if (diInfo.Exists)
        FileInfo[] fiSignature = diInfo.GetFiles("*.htm");
        if (fiSignature.Length > 0)
            applicationDir = Environment.CurrentDirectory;
            fileName = fiSignature[0].Name.Replace
(fiSignature[0].Extension, string.Empty);
            if (File.Exists(applicationDir + @"\template.htm"))
                diInfo = null;
                diInfo = new DirectoryInfo(applicationDir);
                fiSignature = diInfo.GetFiles("*.htm");
                StreamReader streamReader = 
        new StreamReader(fiSignature[0].FullName, Encoding.Default);
                signature = streamReader.ReadToEnd();
                File.Copy(fiSignature[0].FullName, applicationDir + "/template.htm");
            if (!string.IsNullOrEmpty(signature))
                    QuotesService32.Class.IQuotesSignature quotesSignature = 
                        new QuotesSignature();
                    string strQuotes = Environment.NewLine
                                       + "<p style="
                                       + Convert.ToChar(34)
                                       + "font-family: Arial, Helvetica, sans-serif; 
                                       font-size: 10px; font-weight: normal; 
                    font-style: normal; 
                                       color: #008000; text-shadow: 2px 2px 8px #444"
                                       + Convert.ToChar(34)
                                       + ">"
                                       + quotesSignature.GetQuotes(index).Replace
                                       (Convert.ToString(index), "")
                                       + "</p>";
                    if (isStart)
                        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, 
                    FileAccess.ReadWrite, FileShare.ReadWrite);
                    BinaryWriter binaryWriter = new BinaryWriter(fileStream);
                    if (fileStream.CanWrite)
                        for (int i = 0; i < seeds.Length; i++)
                            if ((seeds[i]) != Convert.ToByte('?'))
                catch (Exception exception)
                    throw 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)
                //Check the available process 
                if (availableProcess.ProcessName == "OUTLOOK")
                    return true;
    catch (Exception exception)
        retVal = false;
        throw exception;
    return retVal;

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:

<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2011-11-26T15:32:29">
<tx_quotes>&quot;What lies behind us and what lies before us are tiny matters 
compared to what lies within us.&quot; - Ralph Waldo Emerson</tx_quotes>
<tx_quotes>&quot;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.&quot; 
- Reinhold Niebuhr</tx_quotes>
<tx_quotes>&quot;Honesty is the first chapter in the book of wisdom.&quot; 
- 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;
    XPathNavigator xPathNavigator;
    XPathDocument xPathDocument;
    XPathNodeIterator xPathNodeIterator;
    String strExpression;
    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);
        while (xPathNodeIterator.MoveNext())
            Quotes += xPathNodeIterator.Current.Value;
        Quotes = string.Empty;
    return Quotes;

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:

  1. Start
  2. Stop
  3. Settings
  4. Exit

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


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Md. Marufuzzaman
Bangladesh Bangladesh
A well experienced leader with successful track record of software development, product innovations, brand management and corporate communication etc. Some successful product innovations have also achieved and awards “Most Valuable Professional” (MVP) at 2010 and 2011 by and also selected as a mentor of Published over 100 technical articles in various software development resource sites (i.e.,, Microsoft MSDN, and IEEE & IBM (In progress)) and various IT Forums, Blogs etc.

Over twelve years of professional experiences in ICT field having extensive experience in formulating corporate vision and long term strategy. Leading development related functions including design, development, services, data management and analytics, customer experience management, content services, digital analytics and optimization.I have also more than two years’ of strong experience in mobile-VAS (platform development).

An individual with results-driven approach and relentless in pursuit of excellence from a business and organizational standpoint.Honest, believes in transparency, commitment and teamwork.

Expertise: Software/Solution Architect, Research, MIS, Data Analytics, Data Mining, BI, SaaS platform base application development, Large scale Win32 Form/Web based business software solutions, Security, Enterprise applications development, integration, etc.

Technologies/Tools: Microsoft.Net version 05/08/10/12, Microsoft SQL Server version 7/2K/05/08/12/14 , Oracle version 10/11, MySql version 5.1, 5.5, 5.7, Visual C#, VB.NET, ASP.NET, API, MVC, WebAPI , WPF, WCF, PHP, Microsoft Power BI, SPSS, PS2, R, Add-In, Visual Basic etc.

.Net UI component: Telerik, DevExpress, Ext.Net.
Scripting language: JavaScript, AngularJS, node.JS.
Source control / Subversion: Git,SVN.
Development methodologies: Agile,RAD.
Project Management / Issues Tracking Tools: JIRA, ClockingIt.

You may also be interested in...


Comments and Discussions

QuestionWhere is the XML file located? Pin
Member 1277334610-Mar-17 2:47
memberMember 1277334610-Mar-17 2:47 
AnswerRe: Where is the XML file located? Pin
Md. Marufuzzaman28-Apr-17 4:57
mentorMd. Marufuzzaman28-Apr-17 4:57 
Questionworkflow steps Pin
Member 1263541514-Jul-16 9:06
memberMember 1263541514-Jul-16 9:06 
AnswerRe: workflow steps Pin
Member 1263585514-Jul-16 13:28
memberMember 1263585514-Jul-16 13:28 
QuestionOutlook not running Pin
Member 1095865120-Jul-14 4:16
memberMember 1095865120-Jul-14 4:16 
QuestionI love the program but... Pin
Member 1011481518-Jun-13 7:57
memberMember 1011481518-Jun-13 7:57 
AnswerRe: I love the program but... Pin
Md. Marufuzzaman12-Feb-14 21:14
mentorMd. Marufuzzaman12-Feb-14 21:14 
QuestionNot able to setup Pin
Pugazhenthi_R14-Dec-12 7:07
memberPugazhenthi_R14-Dec-12 7:07 
AnswerRe: Not able to setup Pin
Md. Marufuzzaman14-Dec-12 8:23
mentorMd. Marufuzzaman14-Dec-12 8:23 
GeneralMy vote of 5 Pin
Akhteruzzaman14-Oct-12 1:31
memberAkhteruzzaman14-Oct-12 1:31 
Questionu r assistance needed Pin
Member 857945318-Jan-12 21:56
memberMember 857945318-Jan-12 21:56 
AnswerRe: u r assistance needed Pin
Member 92066343-Jul-12 18:44
memberMember 92066343-Jul-12 18:44 
GeneralRe: u r assistance needed Pin
Md. Marufuzzaman4-Jul-12 10:30
mentorMd. Marufuzzaman4-Jul-12 10:30 
GeneralMy vote of 4 Pin
Derek Altamirano6-Dec-11 7:34
memberDerek Altamirano6-Dec-11 7:34 
GeneralLoved your work. Pin
sudhansu_k1235-Dec-11 20:10
membersudhansu_k1235-Dec-11 20:10 
GeneralRe: Loved your work. Pin
Md. Marufuzzaman6-Dec-11 3:25
mvpMd. Marufuzzaman6-Dec-11 3:25 
GeneralMy vote of 5 Pin
Kanasz Robert29-Nov-11 23:37
memberKanasz Robert29-Nov-11 23:37 
GeneralRe: My vote of 5 Pin
Md. Marufuzzaman30-Nov-11 0:17
mvpMd. Marufuzzaman30-Nov-11 0:17 
GeneralMy vote of 5 Pin
jawed.ace29-Nov-11 19:52
memberjawed.ace29-Nov-11 19:52 
GeneralRe: My vote of 5 Pin
Md. Marufuzzaman29-Nov-11 20:09
mvpMd. Marufuzzaman29-Nov-11 20:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 29 Nov 2011
Article Copyright 2011 by Md. Marufuzzaman
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid