Skip to content

Commit

Permalink
outlook reply and forward
Browse files Browse the repository at this point in the history
  • Loading branch information
openbots-ff committed Mar 11, 2020
1 parent c7f83f8 commit 08edd51
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 7 deletions.
6 changes: 3 additions & 3 deletions taskt/Core/Automation/Commands/OutlookDeleteEmailsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class OutlookDeleteEmailsCommand : ScriptCommand
public string v_SourceFolder { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Provide a filter (Optional)")]
[Attributes.PropertyAttributes.PropertyDescription("Provide a filter (Required)")]
[Attributes.PropertyAttributes.InputSpecification("Enter an outlook filter string")]
[Attributes.PropertyAttributes.SampleUsage("[Subject] = 'Hello'")]
[Attributes.PropertyAttributes.SampleUsage("[Subject] = 'Hello' and [SenderName] = 'Jane Doe'")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_Filter { get; set; }
Expand Down Expand Up @@ -73,7 +73,7 @@ public override void RunCommand(object sender)
}
else
{
filteredItems = sourceFolder.Items;
throw new System.Exception("No filter found. Filter required for deleting emails.");
}

List<MailItem> tempItems = new List<MailItem>();
Expand Down
112 changes: 112 additions & 0 deletions taskt/Core/Automation/Commands/OutlookForwardEmailsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Linq;
using System.Xml.Serialization;
using System.Data;
using System.Windows.Forms;
using System.Collections.Generic;
using taskt.UI.Forms;
using taskt.UI.CustomControls;
using Microsoft.Office.Interop.Outlook;
using Application = Microsoft.Office.Interop.Outlook.Application;

namespace taskt.Core.Automation.Commands
{
[Serializable]
[Attributes.ClassAttributes.Group("Outlook Commands")]
[Attributes.ClassAttributes.Description("This command allows you to manipulate emails with outlook")]
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to manipulate emails with your currenty logged in outlook account")]
[Attributes.ClassAttributes.ImplementationDescription("")]
public class OutlookForwardEmailsCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Provide the source mail folder name")]
[Attributes.PropertyAttributes.InputSpecification("Enter the mail folder you want your emails to come from")]
[Attributes.PropertyAttributes.SampleUsage("**myData**")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_SourceFolder { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Provide a filter (Optional)")]
[Attributes.PropertyAttributes.InputSpecification("Enter an outlook filter string")]
[Attributes.PropertyAttributes.SampleUsage("[Subject] = 'Hello' and [SenderName] = 'Jane Doe'")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_Filter { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Indicate Recipients (; delimited)")]
[Attributes.PropertyAttributes.InputSpecification("Enter the Email Addresses of the recipients in semicolon seperated values")]
[Attributes.PropertyAttributes.SampleUsage("[email protected];[email protected]")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_Recipients { get; set; }

public OutlookForwardEmailsCommand()
{
this.CommandName = "OutlookForwardEmailsCommand";
this.SelectionName = "Forward Outlook Emails";
this.CommandEnabled = true;
this.CustomRendering = true;
}

public override void RunCommand(object sender)
{
var engine = (Engine.AutomationEngineInstance)sender;
var vSourceFolder = v_SourceFolder.ConvertToUserVariable(sender);
var vFilter = v_Filter.ConvertToUserVariable(sender);
var vRecipients = v_Recipients.ConvertToUserVariable(sender);

var splittext = vRecipients.Split(';');

Application outlookApp = new Application();
AddressEntry currentUser = outlookApp.Session.CurrentUser.AddressEntry;
NameSpace test = outlookApp.GetNamespace("MAPI");

if (currentUser.Type == "EX")
{
MAPIFolder inboxFolder = test.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Parent;
MAPIFolder sourceFolder = inboxFolder.Folders[vSourceFolder];
Items filteredItems = null;

if (vFilter != "")
{
filteredItems = sourceFolder.Items.Restrict(vFilter);
}
else
{
filteredItems = sourceFolder.Items;
}

foreach (object _obj in filteredItems)
{
if (_obj is MailItem)
{
MailItem tempMail = (MailItem)_obj;
MailItem newMail = tempMail.Forward();
foreach (var t in splittext)
newMail.Recipients.Add(t.ToString().Trim());
newMail.Recipients.ResolveAll();
newMail.Send();

}
}
}
}

public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolder", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Filter", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Recipients", this, editor));

return RenderedControls;
}

public override string GetDisplayValue()
{
return base.GetDisplayValue() + $" [From: {v_SourceFolder}, To: {v_Recipients}]";
}
}
}
4 changes: 2 additions & 2 deletions taskt/Core/Automation/Commands/OutlookGetEmailsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace taskt.Core.Automation.Commands
public class OutlookGetEmailsCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Provide the mail folder name")]
[Attributes.PropertyAttributes.PropertyDescription("Provide the source mail folder name")]
[Attributes.PropertyAttributes.InputSpecification("Enter the mail folder you want your emails to come from")]
[Attributes.PropertyAttributes.SampleUsage("**myData**")]
[Attributes.PropertyAttributes.Remarks("")]
Expand All @@ -30,7 +30,7 @@ public class OutlookGetEmailsCommand : ScriptCommand
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Provide a filter (Optional)")]
[Attributes.PropertyAttributes.InputSpecification("Enter an outlook filter string")]
[Attributes.PropertyAttributes.SampleUsage("[Subject] = 'Hello'")]
[Attributes.PropertyAttributes.SampleUsage("[Subject] = 'Hello' and [SenderName] = 'Jane Doe'")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_Filter { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions taskt/Core/Automation/Commands/OutlookMoveEmailsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace taskt.Core.Automation.Commands
public class OutlookMoveEmailsCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Indicate whether to move or copy the emails")]
[Attributes.PropertyAttributes.PropertyDescription("Indicate whether to Move or Copy the emails")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Move Emails")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Copy Emails")]
[Attributes.PropertyAttributes.InputSpecification("Specify whether you intend to move or copy the Emails. Moving will remove the emails from the original folder while Copying will not.")]
Expand All @@ -38,7 +38,7 @@ public class OutlookMoveEmailsCommand : ScriptCommand

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Provide a filter (Optional)")]
[Attributes.PropertyAttributes.InputSpecification("Enter an outlook filter string")]
[Attributes.PropertyAttributes.InputSpecification("[Subject] = 'Hello' and [SenderName] = 'Jane Doe'")]
[Attributes.PropertyAttributes.SampleUsage("[Subject] = 'Hello'")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
Expand Down
156 changes: 156 additions & 0 deletions taskt/Core/Automation/Commands/OutlookReplyToEmailsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
using System;
using System.Linq;
using System.Xml.Serialization;
using System.Data;
using System.Windows.Forms;
using System.Collections.Generic;
using taskt.UI.Forms;
using taskt.UI.CustomControls;
using Microsoft.Office.Interop.Outlook;
using Application = Microsoft.Office.Interop.Outlook.Application;

namespace taskt.Core.Automation.Commands
{
[Serializable]
[Attributes.ClassAttributes.Group("Outlook Commands")]
[Attributes.ClassAttributes.Description("This command allows you to manipulate emails with outlook")]
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to manipulate emails with your currenty logged in outlook account")]
[Attributes.ClassAttributes.ImplementationDescription("")]
public class OutlookReplyToEmailsCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Indicate whether to Reply or Reply All")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Reply")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Reply All")]
[Attributes.PropertyAttributes.InputSpecification("Specify whether you intend to reply or reply all. Replying will reply to only the original sender. Reply all will reply to everyone.")]
[Attributes.PropertyAttributes.SampleUsage("Select either **Reply** or **Reply All**")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_OperationType { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Provide the source mail folder name")]
[Attributes.PropertyAttributes.InputSpecification("Enter the mail folder you want your emails to come from")]
[Attributes.PropertyAttributes.SampleUsage("**myData**")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_SourceFolder { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Provide a filter (Optional)")]
[Attributes.PropertyAttributes.InputSpecification("Enter an outlook filter string")]
[Attributes.PropertyAttributes.SampleUsage("[Subject] = 'Hello' and [SenderName] = 'Jane Doe'")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_Filter { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Provide Email Body")]
[Attributes.PropertyAttributes.InputSpecification("Enter the body you want on your email to be sent.")]
[Attributes.PropertyAttributes.SampleUsage("**myData**")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_Body { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Select Email Body Type")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Plain")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("HTML")]
[Attributes.PropertyAttributes.InputSpecification("")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_BodyType { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Attachment File Path (Optional)")]
[Attributes.PropertyAttributes.InputSpecification("Enter the Filepath of the file you want attached.")]
[Attributes.PropertyAttributes.SampleUsage("c:sales reports\fy06q4.xlsx")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)]
public string v_Attachment { get; set; }
public OutlookReplyToEmailsCommand()
{
this.CommandName = "OutlookReplyToEmailsCommand";
this.SelectionName = "Reply To Outlook Emails";
this.CommandEnabled = true;
this.CustomRendering = true;
this.v_BodyType = "Plain";
}

public override void RunCommand(object sender)
{
var engine = (Engine.AutomationEngineInstance)sender;
var vSourceFolder = v_SourceFolder.ConvertToUserVariable(sender);
var vFilter = v_Filter.ConvertToUserVariable(sender);
var vBody = v_Body.ConvertToUserVariable(sender);
var vAttachment = v_Attachment.ConvertToUserVariable(sender);

Application outlookApp = new Application();
AddressEntry currentUser = outlookApp.Session.CurrentUser.AddressEntry;
NameSpace test = outlookApp.GetNamespace("MAPI");

if (currentUser.Type == "EX")
{
MAPIFolder inboxFolder = test.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Parent;
MAPIFolder sourceFolder = inboxFolder.Folders[vSourceFolder];
Items filteredItems = null;

if (vFilter != "")
{
filteredItems = sourceFolder.Items.Restrict(vFilter);
}
else
{
filteredItems = sourceFolder.Items;
}

foreach (object _obj in filteredItems)
{
if (_obj is MailItem)
{
MailItem tempMail = (MailItem)_obj;
if (v_OperationType == "Reply")
{
MailItem newMail = tempMail.Reply();
Reply(newMail, vBody, vAttachment);
}
else if(v_OperationType == "Reply All")
{
MailItem newMail = tempMail.ReplyAll();
Reply(newMail, vBody, vAttachment);
}
}
}
}
}

private void Reply(MailItem mail, string body, string attPath)
{
if(v_BodyType == "HTML")
mail.HTMLBody = body;
else mail.Body = body;

if (!string.IsNullOrEmpty(attPath))
mail.Attachments.Add(attPath);

mail.Send();
}

public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_OperationType", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolder", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Filter", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Body", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_BodyType", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Attachment", this, editor));
return RenderedControls;
}

public override string GetDisplayValue()
{
return base.GetDisplayValue() + $" [From: {v_SourceFolder}]";
}
}
}
2 changes: 2 additions & 0 deletions taskt/Core/Automation/Commands/ScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace taskt.Core.Automation.Commands
[XmlInclude(typeof(OutlookGetEmailsCommand))]
[XmlInclude(typeof(OutlookMoveEmailsCommand))]
[XmlInclude(typeof(OutlookDeleteEmailsCommand))]
[XmlInclude(typeof(OutlookForwardEmailsCommand))]
[XmlInclude(typeof(OutlookReplyToEmailsCommand))]
[XmlInclude(typeof(ActivateWindowCommand))]
[XmlInclude(typeof(GetRegexMatchesCommand))]
[XmlInclude(typeof(MoveWindowCommand))]
Expand Down
2 changes: 2 additions & 0 deletions taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ public static Dictionary<string, Image> UIImageDictionary()
uiImages.Add("OutlookGetEmailsCommand", taskt.Properties.Resources.command_smtp);
uiImages.Add("OutlookMoveEmailsCommand", taskt.Properties.Resources.command_smtp);
uiImages.Add("OutlookDeleteEmailsCommand", taskt.Properties.Resources.command_smtp);
uiImages.Add("OutlookForwardEmailsCommand", taskt.Properties.Resources.command_smtp);
uiImages.Add("OutlookReplyToEmailsCommand", taskt.Properties.Resources.command_smtp);
uiImages.Add("ErrorHandlingCommand", taskt.Properties.Resources.command_error);
uiImages.Add("TryCommand", taskt.Properties.Resources.command_try);
uiImages.Add("CatchExceptionCommand", taskt.Properties.Resources.command_try);
Expand Down
2 changes: 2 additions & 0 deletions taskt/taskt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@
<Compile Include="Core\Automation\Commands\ExcelWriteRangeCommand.cs" />
<Compile Include="Core\Automation\Commands\FinallyCommand.cs" />
<Compile Include="Core\Automation\Commands\EncryptionCommand.cs" />
<Compile Include="Core\Automation\Commands\OutlookForwardEmailsCommand.cs" />
<Compile Include="Core\Automation\Commands\OutlookGetEmailsCommand.cs" />
<Compile Include="Core\Automation\Commands\OutlookMoveEmailsCommand.cs" />
<Compile Include="Core\Automation\Commands\OutlookReplyToEmailsCommand.cs" />
<Compile Include="Core\Automation\Commands\ParseJsonModelCommand.cs" />
<Compile Include="Core\Automation\Commands\RemoteAPICommand.cs" />
<Compile Include="Core\Automation\Commands\RemoteTaskCommand.cs" />
Expand Down

0 comments on commit 08edd51

Please sign in to comment.