Processing an email in Outlook

I need some help. At runtime, when processing an email in Outlook, I want to dynamically append an additional value to the subject line (for example: “Bid No - 1234”) and then move that email to another folder

Hi @T_Y_Raju ,

You can do something take the current value of subject and assign back to same.

Example
mail.Header[“Subject”] = mail.Header[“Subject”] + “Additional value that you want to append”

See if it helps
Thanks

For any operation with Outlook, or rather any Microsoft Office software like Word, Excel, PowerPoint.. use c# code and Microsoft.Office.Interop directly. It’ll be more efficient and less error prone. Anything else is just wrapper based on this.

When you move emails, make sure you use the Entry ID (GetItemFromID(entryId)). Don’t move email from inside a collection directly. It’ll mess up the collection and you end up loosing track of it.

@T_Y_Raju

i dont think you can edit subject line while moving it

you might need to resend with new subject and then move

cheers

A little chatgpt and voila:

using Outlook = Microsoft.Office.Interop.Outlook;

Outlook.Application outlook = new Outlook.Application();
Outlook.NameSpace ns = outlook.GetNamespace(“MAPI”);

// Example: get Inbox
Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

// Get first mail
Outlook.MailItem mail = inbox.Items[1] as Outlook.MailItem;

if (mail != null)
{
mail.Subject = “New Subject Line”;
mail.Save();
}

can this be done at the runtime

What do you mean at runtime? While Outlook is running? yes. But for long execution (e.g. processing thousands of emails in a loop), your Outlook may appear stuck temporarily.

@T_Y_Raju Yes, it can be done at runtime if you are working with the actual Outlook mail item. The usual flow is:

1.get the mail item
2.update Subject by appending your value
3.call Save()
4.then move it to the target folder

So it’s more of an edit + save + move approach, not a resend.

If you are handling many emails in a loop, using the mail EntryID / GetItemFromID approach is safer, as mentioned above, because moving items can sometimes affect the original collection.

If the data is purely for automation, then look at MS Graph’s capability to add “extension” data to a O365 Outlook MailMessage.

Here a screenshot of a MailMessage where I attached such invisible data. May I point out: structured data!

Can even be offered as an Outlook Add-In to the user, for email triage.

Data is stored as long as the mail is not moved into another mailbox.