Create a Task from an Email using a Rule

I regularly convert many of my emails into tasks, is there a way to create a rule that will automatically convert emails with a specific subject line, into a task?

Sure, you can use a simple script that creates a task from an email and use it with a Run a Script rule. We also added a second code sample that creates a task from the message you are reading in the reading pane.

You can customize the script to set a category or due date (or any other fields supported in Tasks). To calculate the due date, you'll use the DueDate property and add a whole number to the Received date. If you prefer to change the Start date, you would add a whole number to the start date line. If you use a category that is not in your Categories list, the color category field in the view will be colorless as the category is not in the master list.

To copy attachments from the messages to the task, get the CopyAttachments function and add it at the end of the task macro. Then add this code before the .save

If Item.Attachments.Count > 0 Then
CopyAttachments Item, objTask
End If

Send a Task Request

If you want to send a Task Request, you need to Assign it and add the Recipient. You can use either the full email address or the GAL alias, or even the person's display name, provided the name can resolve to an entry in your address book or GAL. I recommend using the address only because it can't resolve to the wrong person.

You'll need to add .Assign to the With objTask code block, along with .Recipients.Add "email@address.com" line. You'll also need to change .Save to .Send

If you use the user's name or alias, you may need to Resolve it using code before it's sent. .Assign goes in the With objTask code block, but the Recipient is added outside of the With statement, then it's sent.

The DIM statement goes at the top of the macro with the other DIM statements.

Carol asked how to add a category to the tasks. This is easy if you want one category for all tasks - just place this line before the objTask.Save line:

objTask.Categories = "keyword"

To assign different categories based on different keywords in the subject, you can use an IF statement for a couple of keywords but should use an array for a larger number of keywords. Instructions are at Using Arrays with Outlook macros.

Save to a different tasks folder

You can save the task to a different folder by adding two lines to the code. This example saves it to a Task folder in a different data file, in this case, a Sharepoint task list that is linked to Outlook.

You can also use a different folder in the mailbox. When the folder is the same level as the Tasks folder, using the example below.

' You need the GetFolderpath function from
' http://slipstick.me/qf#GetFolderPath
Set SPSFolder = GetFolderPath("SharePoint Lists\Slipstick - Tasks")
Set objTask = Application.CreateItem(olTaskItem)
' do whatever
'
objTask.Save
' After you save the task, move it to the other folder
objTask.Move SPSFolder

Create the rule

Create a rule using the condition and choose the action "Run a Script", choosing the ConvertMailtoTask script you pasted into the VBA editor. Complete the rule.

When a new message arrives meeting the conditions in the rule, the script runs and creates a task out of the message.

Create Task from the selected message

Jason wanted to know if we could use the code with a button to create a task from a selected message.

To do this, we needed to modify the original code just a little. To use it, create a command on the ribbon or toolbar and assign the macro to it. When you are reading a message in the reading pane, you can click the button to create a task.

This code doesn't work with open messages, but a little more tweaking can change that.

SimplyFile helps you file incoming and outgoing messages to the right Outlook folder with one click of a mouse. SimplyFile's state of the art algorithm learns as you file messages and suggests destination folders for filing. All you have to do to send a message to the right folder is click a button. SimplyFile also includes buttons for turning messages into Tasks and Appointments. Compatible with Outlook 2000, 2002, 2003 and 2007. Version 2.3.4.106.

Related Posts:

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Would it be possible to assign this event to a button (macro) by customizing the toolbar of the message form? I would like to be able to trigger the event while reviewing the message, as opposed to creating the task based on a rule.

Hello,
After a solid 3 hours of searching for solutions to what I thought would be a standard feature, I was amazed that the code you listed above worked!

The wrinkle: I would like the created task to be created in a shared task folder rather than my default task folder... ie, I have a custom task folder called "Freight" which can be accessed by anyone in our freight department and I want the auto-generated task to be there.

How can I add a red flag for the task. Or is there any other way that I could get my mailconverted tasks to get shown to me more easier. Now I have to go to tasks and select right task list to see these converted.
if I would get a flag on it it would come up more!

Tasks have flags by default. You might want due date & reminders -
objTask.DueDate = objMail.ReceivedTime + 3 ' due in 3 days
objTask.ReminderSet = True
objTask.ReminderTime = objTask.DueDate - 0.25 ' this is 6 hours before its due

A filtered view might help - or assigning a category. Create a category and assign a color then add objTask.Categories = "Category-name" above the line that saves it. Filter task list shows how to hide flagged email, but you can use the same method to hide or show tasks meeting other conditions.

is it possible to add the first line of the body of the email to a user defined field? My email will have the name of the person sending the request, I have a user defined field in my task for Requested by.

objTask.customfield = left (Item.body,20) 'where 20 is the # of characters you want from the first line

The results might be goofy if the first line is shorter than 20 (or whatever number you choose), so you'll probably want to get the line length and calculate it. I don't have any code samples for that committed to memory though.

Out of interest, how much additional coding would it take to check if a particular task already existed and update that task rather than creating a new one? e.g. any email coming from address aaa@bbb.com would cause the same task to be updated with the subject line of the email.

CODE LIKE EMAIL TO TASK CAN ANYONE HELP?
I have an Outlook add-in called Credenza which looks to be based on the Journal feature in OL , is there a way to modify the code so an email could be made into one of these Credenza cases automatically?
Kind of like email to task just email to case that has a certain format and form?

This works awesome and so grateful I was able to stumble across this tip.
I have a requirement to move the task into a Task List linked to Sharepoint.
Would you by chance know how to save the task into the sharepoint list instead of the regular list within Outlook?

Add the two bolded lines to the code and change the name of the tasks folderSet SPSFolder = GetFolderPath("SharePoint ListsYour Site - Tasks")
Set objTask = Application.CreateItem(olTaskItem)
-- snipped code --
objTask.SaveobjTask.Move SPSFolder

The code is great and worked the first time I tried it. I deleted the test tasks it created, but now it does not create new tasks when I run it. I have tried restarting Outlook, but it still fails. Restarting the computer, and it still fails. The code is still the same in VBA.

I am in a corporate domain environment. Could that be disabling this functionality?

If it worked in the test on the same machine, it's not the corp blocking it. Did you check the macro security settings? File, Options, Trust Center, Macro security in Outlook 2010 and 2013 or Tools, Macros, Security in older versions. Is the rule enabled?

I'd like to trigger this script by setting up a rule that runs whenever Outlook receives an email with certain words in the subject line. I am running the Outlook client on several computers, none of which is guaranteed to be running Outlook all the time (i.e. I use a laptop at work, and when I am travelling it is not on). Is the script stored on the Exchange server, so it will be available to run whenever it is triggered by the rule? If not - what happens when the rule triggers the script, but the script is on a machine which is not running?

No, the script is not stored on the server - it's in Outlook and Outlook needs to be running to use it. The rules that use Run a script action are 'this machine only' rules so they only run on the specific computer.

Dear Diane.
I would first like to applaud your work - it is right on the point, clearly structured and helpful.
I have been looking for a pragmatic approach to manage the "to-dos vs. tasks" problem in Outlook for months (if not years). Your solution goes very much into that direction, however I am still trying to figure out if there is a way to also solve the focus on flags and the automatization feature (e.g. with repetitively running script?). I have also found the following code which might be useful for an expert like you (http://xmindlook.net/xmindlook-sync/documentation/tips/email-to-task-conversion).
I would be very greatful for your help!
M

Desired solution:
Flagged emails shall be automatically (e.g. every couple minutes) converted into corresponding tasks
Desired behavior:
* for newly created task (placed in default task folder on exchange, mail itself and mail-attachments included as attachments in task, email subject set as task title, email receival date set as start date in task, other fields like category left empty (will be set manually later on))
* for original mail (flag disabled (empty), text "[Task] " added at the beginning of the mail subject)

Changing flags to task every few minutes won't work, outlook doesn't have a timer feature. You can trigger macros from reminders though - so it is possible if you need some automation. If you use a lot of reminders you can trigger it with any reminder, otherwise, you'll need to use a recurring task or appointment. (If you send a lot of mail, item send event could trigger the macro). In the case of the macro at the other site, where you need to affect synced items, triggering a macro by an event probably the best option.

If you want to create the task as you flag an item, use an item change event that creates the task when the item is flagged. See the quick flag example here.

Hi, this site is great! I wanted to use this code but I need it to run when I am not in the office (as I want to send myself emails which will create tasks) - I see from what you say that the code lives on the machine. So, looking at it from a new angle, is it possible to have a macro that runs when I launch Outlook which would check my inbox for emails with "Task" in the subject for example and create tasks when it finds one?

Here is a version that checks new mail as it arrives in Outlook. It's really no different than using rules, but can handle processing a larger number of new messages better. It would also be possible to call a macro from Application_Startup, but that would only process existing email, not new mail as it arrives. Another option is using reminders to trigger a macro that checks the Inbox. This should run before rules, so any rule that adds categories or moves the message shouldn't affect it.

This version looks for the word "Task:" at the beginning of a message, then creates a Task due tomorrow.

So easy to use! Thanks. I also added a If unread = true condition so it would only apply the code to new, unread messages. otherwise it kept adding every message that met my conditions, even if they were old, my task list got very long!

What type of email account do you use? Are you right clicking on a message or going to Rules and Alerts? If you right click, you need to click Advanced. Run a Script is near the bottom of the Actions list of the Rules Wizard.

Is there a way to have the email as an attachment, but NOT have the body of the email pasted into the notes area of the task? I would rather keep that area clean for things I need to know about the task, plus the attachment is already there

Perfect! I was able to stop the body text as well as get it to categorize and set dates the way i want. Next question, how can I combine this with the quickflag one you posted earlier? If I forget to BCC myself, I would like to be able to go to the the follow up flag and get the same result. How do I combine that code with what I've already done?

I think I might be totally confused and I consider myself an advanced user of Microsoft Office. Since I don't have much experience in the way of writing scripts, is it possible to get a step-by-step of this process? I have been trying to convert my emails into a task by way of creating a rule. Currently, I have a rule setup to create a task but it's just the email sitting in my task folder. Please help!

Can you provide code to the do the same thing, but to also set the DueDate at ReceivedTime + 2 WORK days? I've searched for hours and can't seem to find something I can work with...I am a novice to VB.

In addition to the post above (on 7/12/13), is it possible to create something that would only execute the code if the email is an original email and not a reply or forward of an email? I plan to use this in conjunction with an Outlook rule to run this script if the Subject meets word based criteria. But I would only want it to run on the original email and not any subsequent related emails I might receive. Any help you can provide is much appreciated.

Hello, I followed these steps using the first code at the top of this page, last Friday. The rule worked as expected. Came in this morning, and now the script will not run. Everything else in the rule works (alert, pop up notice etc), but the task is not created. Outlook 2010

Your coding solves a big issue in my organizational management skills and I thank you! However, I have had the same experience Chris who posted on 9/16/13 - I have followed the steps using the first code at the top of the page - the rule WORKED - now the rule does NOT work - Everything else in the rule works (such as marking item as read), but the task is not created. I checked Macro Settings in Trust Center and the only thing that is checked is "Notifications for digitally signed macros, all other macros disabled". I am running Outlook 2013 (Office 365 Enterprise). Can you help me? I do not understand the security settings in Outlook. Thanks!

I used your code to create task for email with certain words in subject. Also ı want to modify due date of task with information in the email. I tried to use code below but it did not work. Please help me about it

Hi again,
when ı used the code below, it created the tasks buts due date of task is 30.7.2019 so I think ı could not get the right text parts of task body. Is there a way to see which parts I get from the body with code?

use debug.print after you set the variables - show the Immediate windows (Ctrl+G or the view menu) and see if the values are correct. The only thing I can think is that the date serial format is not putting the numbers in the correct order - it worked here with the US date format (mm/dd/yyyy).

Hi, I've been using this excellent code successfully for some while. Now I would like to make one small change I'm unsure how to do it. I have created a task form of my own and saved it personal forms library, I have called it "my task". How can I adapt the code to use my form instead of the default task form.

I think I know what I need to change, but don't know what to change it to!!!

Thank you all, this VBA Code used to work great for us. We used it with creating / syncing the task to a linked Office 365 Sharepoint-Tasklist.
Too bad, since the Office 365 2013 Upgrade it´s not working any more. MS changed the sync to outlook feature in a big way. Now new task are created/synced always first as personal tasks and the GetFolderPath function (see below) to move the tasks to the sharepoint list is not working anymore.
Looking for some help how to make this work again. Is there a way to add a new task-item to sharepoint task list from VBA?
Thank you in advance for any advice and code samples.

This is great and I want it to work. I copy/pasted the code in the article and get a syntax error... does anyone know what to do with this? It happens for the first line of code (Sub ConvertMailtoTask(Item As Outlook.MailItem))

Diane:
First, the help you provide and columns you write are excellent. And that you have time to reply and provide detailed responses to everyone is amazing. I can't thank you enough.

I would like to tweak the code a bit so that the resulting task includes the From/Sent/To/Subject info from the email header above the body text of the email. In other words, it would appear just as if you selected a received message, clicked forward, and copied all of the text below the solid line that Outlook inserts above the From: line.

I'm using both the Outlook Rule to "Create a task from an Email" and the Macro for creating a task from a selected message and will be using any suggestions you provide in each. Thank you very much!

Thank you, it works. Another question: Is it possible to read and write to userdefinedfields from code? For instance a field I called "OneWayTravelDistance". How do I access this userfield from script? Do you have an example?

I am wondering if it's possible to get a cell value, say A1, from Excel and set it as the objTask.DueDate and the objTask.ReminderTime. I would assume the format in the cell would have to be mm/dd/yyyy hh/mm. Your help would be greatly appreciated.

Hi Diane,
You have very useful information on the site and I thank you for that.

I was wondering if it's possible to grab a cell value, say cell A1, from Excel and set it as the objTask.DueDate and objTask.ReminderTime. I think the cell format would have to be like mm/dd/yyyy hh:mm. I'm not sure how to call the Excel sheet and what to set objTask.DueDate and objTask.ReminderTime equal to. Your help is greatly appreciated.

Thanks for the help, this works great. I have added custom fields to the task form and renamed it. When I run this script though it always creates the task using the default task form. Is there away I can have it create the task using the custom form I have already made?

Yes, you need to replace the code that creates the new task with code that uses the template.

Set objTask = Application.CreateItemFromTemplate("template.oft")
If it's a published form, try the published form name "ipm.task.mine", if that doesn't work , use item.add:
Set objtask = Items.Add("ipm.note.name")

I am having some trouble. When I try using the first line of code it prompts me to enter a file path after I enter the published form name. I have the custom form saved in my personal form library but I am not sure what the file path is. When I use the Item.add code it highlights red when I try and save the code and gives me a syntax error when I run it.

Also I had the word "with" in the name of the custom task form. This appeared to give me issues when running the code. I renamed it removing "with", and I stopped getting that error. Should I not be using "with" in custom form names?
Thanks,

Thanks for this tutorial,
I am trying to create 2 tasks from 1 email with the code you provided and a rule to check mail when it arrives. I have been unsuccessful in getting the second task created. Here is my latest attempt (code below). Can you please let me know what I am doing wrong? I have placed it in ThisOutlookSession. The first task is created but I cant get the code to create the second task. Thanks in advance for your help.

Thank you for your very kind assistance,
I will make the change you suggested. You may want to do the same to the response you posted to Dave September 26, 2013 at 9:11 am. That is where I found the code to add the additional task. Thanks again for your help, Keep up the fine work.

All of this has been amazing! Thank you! If I wanted to move the email that I created the task from to a sub folder under the inbox what would I need to add? We are non-profit specialty hospital and this simple script has become invaluable to us. Thank you for your generosity in sharing your knowledge!

You need to use the code in the section for "Save to a different tasks folder" and use the location of the second tasks folder in the code then copy it. It's also possible to set the folder and Add the task to it - either method works well but I don't have a sample on this page that uses Add.

if you want to use a rule and only turn mail from account 2 into tasks, you can choose the sending account in the rule.

I tried changing the account sending the rule, and it still defaulted to email1.

I will research further on how to find how to set and add the outlook object to it in outlook vba somewhere. Thank you for pointing me in the right direction. If I am successful, I will post my findings.

I've cobbled together an Outlook (2010) email-to-task VBA script that does exactly what I need it to EXCEPT for one thing: I want to copy the name of the Sender to the "Contacts..." field at the bottom of the Task window. Any tips?

Set objMsg = Nothing
Set objTask = Nothing
End Sub
Sub CopyFullBody(sourceItem As Object, targetItem As Object)
Dim objDoc As Word.Document
Dim objSel As Word.Selection
Dim objDoc2 As Word.Document
Dim objSel2 As Word.Selection
On Error Resume Next
' get a Word.Selection from the source item
Set objDoc = sourceItem.GetInspector.WordEditor
If Not objDoc Is Nothing Then
Set objSel = objDoc.Windows(1).Selection
objSel.WholeStory
objSel.Copy
Set objDoc2 = targetItem.GetInspector.WordEditor
If Not objDoc2 Is Nothing Then
Set objSel2 = objDoc2.Windows(1).Selection
objSel2.PasteAndFormat wdPasteDefault
Else
MsgBox "Could not get Word.Document for " & _
targetItem.Subject
End If
Else
MsgBox "Could not get Word.Document for " & _
sourceItem.Subject
End If
Set objDoc = Nothing
Set objSel = Nothing
Set objDoc2 = Nothing
Set objSel2 = Nothing
End Sub

Diane - thanks for your help so far. Something I didn't state in my original request was that almost 100% of the emails I'm dealing with are from internal personnel, over Exchange. I apologize for not being clear on this.

So, I guess my clarified requirements are now:

1. If sender is in Contacts, add contact to objTask.Links

And then:
* If sender is not in Contacts, create in Contacts, and then add contact to ObjTask.Links

Or, even better:
* If sender is not in Contacts, find sender in Exchange address book, add (create?) to Contacts, and then add contact to ObjTask.Links

I'm having a couple of issues with the macro below. When I assign it to someone, it is making them the owner (I would like to be the owner and have it assigned to the person), and the start date is being entered 12/31/1899 (and is showing 5000 days late). I'd also like to make sure I have the "Copy Attachement" portion correct.

Thanks for your previous assistance. I have one more question... I get emails that have attached tasks to them, Right now I drag the attachment to the task button then up to the Task folder to get it on my task list. Is there a quick script that I can execute that will take the attachment and move it to my task list? I plan to execute such a script as part of the rule that already grabs these emails and moves them to a specific folder. Any ideas or sample script will be greatly appreciated. Thank you!

I'm facing a situation here which I want to create a task from a SENT message using a rule. I can only run a script from a message I receive. Is it possible to run a script from a sent message, using a rule?

Do you want it to automatically create the task? You'll need to use an itemadd macro and watch the sent items folder. You could also use an itemsend macro to create a task after you hit Send but before the item is sent.

you only need Set fldTasks = ns.GetDefaultFolder(olFolderTasks)
Try changing this: Dim tasksItems As Outlook.taskitem
if you have a second tasks folder at the same level as the default tasks, you'd use Set fldTasks = ns.GetDefaultFolder(olFolderTasks).parent.folders("foldername")

Do you have more than one account in the profile? If the tasks is in a different data file, you'll need to get the folder using a different method.

Hi. Your site and your examples are very useful (and even fun to read). I have a question: I want to do something similar to above except I want to be able to flag a message for follow-up, and then get a prompt to rename the task to something else. As a super bonus, I would like a prompt to get the flag date picker (choose a start and due date).
This would be useful for example if I sent an email requirement to a delegate and I bcc myself, then I'd have a rule to catch all incoming bccs and automatically flag them and give me a choice of due date and also let me customize the task title.
Or if I have an email that requires action from me I could use this script to flag it with a choice of start date and then prompt to let me customize the task title.
Thank you for any attention you can provide.

This seems to have worked for me however when doing tests I'm not receiving a 'completed' status report. When manually creating a task, there's a check box that needs to be selected in order to receive updates... is there a way to get this into a code? I hope you can help. thanks so much in advance.

That is only available if you create a task request - but yes, it can be set using VBA AFAIK. When you use the following snippet in the macro, it creates a task request and both keep an updated copy and send status report are checked.
With objTask
.Assign
.Recipients.Add "drcp@cdolive.com"
.Subject = Item.Subject
.StartDate = Item.ReceivedTime
.Body = Item.Body
'.Send
.Display
End With

Thanks for the quick reply! However, I tried this as stated in your original notes. It is not sending a status report to the sender from the recipient once the task is marked complete. I need the 'Completed status report' to be sent to the sender.

Okay. I understand. 2 questions... Is there a code I can use to get the task assigned by the sender so that when I mark it complete the status report gets sent to them? Or would it be best to have the macro send an updated message? We are looking for something to be automatic, preferably to run on a script

i don't think you can set the task to be from the sender, it would be easier to generate an email. The email can be automatic - it'll look for a task to be marked compete and kick in when that happens.

I may be very confused at this point.... I took the code sample you made and entered both mine and my supervisors emails, when I ran a test nothing happened. heres the code below.... what am I doing wrong? should the create task go above the create mail item?

I receive emails with the subject "Incomplete task notification" from Danielle@century21city.net, frontdesk@century21city.com & century21city@att.net. I'd like all of those emails to be turned into tasks upon receipt into my inbox. Then once I mark those tasks complete, I want an automatic email with the original emails subject (so that the message pairs in the inbox under the correct thread) to be sent to Danielle@century21city.net- saying "task completed". how can I turn this into a macro to run a script.

I hate to ask for so much help, but I've been stuck on this for quite sometime. Can you refer me to a website that will help me build macro codes on my own?

'** This goes in thisoutlooksession
Public WithEvents OlItems As Outlook.Items

Public Sub Initialize_handler()
Set olItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks).Items
End Sub

if all responses will go to one address, it makes it easier - you won't need to set the user property.

Use this in the sub that sends the 'task is complete' message:
With objMsg
.To = "alexis@century21city.com"
.Subject = Item.Subject 'gets task subject
.Body = "Task Completed"
.Display ' use .send to automatically send it
End With

and this to create the task - it should be what you used before:
Sub ConvertMailtoTask(Item As Outlook.MailItem)
Dim objTask As Outlook.TaskItem

There aren't many sites that will help you build macros - most expect you to have some knowledge of what you are doing so they aren't necessarily friendly towards beginners. msdn.microsoft.com and outlookcode.com are good resources, outlookforums.com, stackexchange.com and the MSDN forums are good if you have a question.