Click here to Skip to main content
11,930,018 members (42,298 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked

Rename Attachments in Outlook

, 7 Apr 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Rename attachments before sending any email


To be honest, I created this solution to solve my problems and I hope it solves yours too. I couldn't find something like this while I searched online for long.

Sometimes, we need to forward an email which has an attachment. Sometimes, we create a new document and email it directly from File menu as attachment. In these cases, the file name may not be what we would like to send as (Document1.docx, Book1.xlsx, Powerpoint1.pptx, etc.). Sometimes, the date in the file name is incorrect or there is a spell error.

Outlook or any other tool in the internet (as far as I could search) doesn't solve this problem. So, I created a simple tool using C# to allow me to edit the file name on the fly.


I was hoping that someone would have created this tool already but couldn't find it anywhere... Thus I prepared it myself.

Using the Code

Ideally, the best way to handle this would have been to edit the context menu tool button that said "Rename Attachment". Clicking the button should have saved the file in a temporary directory, renamed it and then should have reattached it. The original file should have been deleted.

However, I wasn't successful in adding the button to the right click menu and hence I chose a different approach. I used a window form to display whenever a mail was sent. This form offers an option to rename attachments.

The approach was is as below:

  1. Catch any mail going out.
  2. List all attachments. Filter out the extension and offer file name for renaming.
  3. For easy renaming, create textboxes on the fly for each attachment.
  4. Once clicked OK, save the file as new filename, re - attach the email, delete the old attachment and send the mail.
  5. Use a timer to ticket after a while and delete this temporary file also.

The key piece of the code is below:

//Handle itemsend event to handle mail sent event.
private void ThisAddIn_Startup(object sender, EventArgs e)
      Application.ItemSend += 
       new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler

//capture any mail going out
void Application_ItemSend(object Item, ref bool Cancel)
      //Use mail item as mail captured
      Microsoft.Office.Interop.Outlook.MailItem mailItem = 
      	Item as Microsoft.Office.Interop.Outlook.MailItem;

      if (mailItem != null)
        var attachments = mailItem.Attachments;

        if (attachments.Count == 0)

        RenameForm form = new RenameForm();
        //Add textbox for each attachment
        Dictionary<int, Microsoft.Office.Interop.Outlook.Attachment> 
        storedAttachments = new Dictionary<int, Microsoft.Office.Interop.Outlook.Attachment>();
        int i = 0;

        foreach (Microsoft.Office.Interop.Outlook.Attachment attachment in attachments)
          form.AddAttachmentDetail(i, attachment);
          storedAttachments.Add(i, attachment);

        DialogResult result = form.ShowDialog();

        if (result == DialogResult.OK)
          string tempFolder = Environment.GetFolderPath
          if (!tempFolder.EndsWith("\\"))
            tempFolder += "\\";

          List<string> filesToDelete = new List<string>();

          int j = 1;

          foreach (var keyValue in form.RenameRequired)
            if (keyValue.Value)
              storedAttachments[keyValue.Key].SaveAsFile(tempFolder + form.NewNames[keyValue.Key]);


          foreach (var keyValue in form.RenameRequired)
            if (keyValue.Value)
              mailItem.Attachments.Add(tempFolder + form.NewNames[keyValue.Key]);
              filesToDelete.Add(tempFolder + form.NewNames[keyValue.Key]);

          Timer timer = new Timer();
          timer.Interval = 120000;
          timer.Tick += timer_Tick;
          timer.Tag = filesToDelete;
        else if (result == DialogResult.Abort)
          Cancel = true;

In order to use this tool in Outlook 2010 (I have tested only this version), we need to install the following at least:

  1. .NET 4
  2. Microsoft Office 2010: Primary Interop Assemblies Redistributable
  3. Visual Studio Tools for Office Runtime


Points of Interest

It is not a very clever piece of code and I am sure that there are improvements possible to use... But I was hoping to achieve the results first and I am sure that new versions are possible. The idea was that these things are possible in Outlook and it is only a matter of looking at things differently.

My next interest is to create a project management tool through Outlook programming.


  • Version 1


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


About the Author

Som Shekhar
India India
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionGetting Installation Error Due To Certificate Pin
Member 121076132-Nov-15 8:36
memberMember 121076132-Nov-15 8:36 
QuestionHow can we change, read and edit the excel or word attachment Pin
varunmaggo11-Nov-13 23:30
membervarunmaggo11-Nov-13 23:30 
AnswerRe: How can we change, read and edit the excel or word attachment Pin
Som Shekhar16-Dec-13 20:30
memberSom Shekhar16-Dec-13 20:30 
QuestionIs the source download not working? Pin
Yanaung77714-Jul-13 18:18
memberYanaung77714-Jul-13 18:18 
AnswerRe: Is the source download not working? Pin
Som Shekhar16-Jul-13 7:08
memberSom Shekhar16-Jul-13 7:08 
GeneralRe: Is the source download not working? Pin
Member 1015709817-Jul-13 15:30
memberMember 1015709817-Jul-13 15:30 
GeneralRe: Is the source download not working? Pin
Som Shekhar19-Jul-13 9:56
memberSom Shekhar19-Jul-13 9:56 
GeneralRe: Is the source download not working? Pin
Som Shekhar16-Dec-13 20:32
memberSom Shekhar16-Dec-13 20:32 
AnswerRe: Is the source download not working? Pin
Som Shekhar16-Dec-13 20:32
memberSom Shekhar16-Dec-13 20:32 
SuggestionNipping the problem in the bud Pin
mrchief_20009-Apr-13 7:28
membermrchief_20009-Apr-13 7:28 
GeneralRe: Nipping the problem in the bud Pin
Som Shekhar9-Apr-13 8:11
memberSom Shekhar9-Apr-13 8:11 
QuestionNot an article Pin
OriginalGriff14-Dec-12 9:23
mvpOriginalGriff14-Dec-12 9:23 
AnswerRe: Not an article Pin
Som Shekhar14-Dec-12 16:25
memberSom Shekhar14-Dec-12 16:25 
AnswerRe: Not an article Pin
Som Shekhar14-Dec-12 16:27
memberSom Shekhar14-Dec-12 16:27 
GeneralRe: Not an article Pin
_ Kunal Chowdhury _15-Dec-12 21:12
mvp_ Kunal Chowdhury _15-Dec-12 21:12 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 8 Apr 2013
Article Copyright 2012 by Som Shekhar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid