Facing issue :Send Email With Key Stroke on Send Button

activities

#1

Hello All,
I am facing issue when I tried to send email with applying key stroke in send button . Below is my code same code working in VS2017 button when I tried to create nugget and implemented in Uipath command not able to hit Send keystroke . Please help me out I already wasted lot of time to figure out.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Net.Mail;
using System.Net;
using Microsoft.Office.Interop.Outlook;
using System.Diagnostics;
using System.IO;
using System.Data;
using System.Windows.Forms;
using System.Activities;
using System.ComponentModel;
using System.Threading;
using System.Runtime.InteropServices;

namespace CustomSendMailUtility
{
//method to send email to outlook
public class CustomSendMailUtility:CodeActivity

{
    [Category("Input")]
    [RequiredArgument]
    public InArgument<String> toValue { get; set; }

    [Category("Input")]
    [RequiredArgument]
    public InArgument<String> subjectValue { get; set; }

    [Category("Input")]
    [RequiredArgument]
    public InArgument<String> bodyValue { get; set; }

    [Category("Input")]
   [RequiredArgument]
    public InArgument<String> attachments { get; set; }

    [Category("Output")]
    [RequiredArgument]
    public OutArgument<String> Flag { get; set; }

    public Outlook.Application oApp;
    public Outlook._NameSpace oNameSpace;
    public Outlook.MAPIFolder oOutboxFolder;


    protected override void Execute(CodeActivityContext context)
    {
        oApp = new Outlook.Application();
        oNameSpace = oApp.GetNamespace("MAPI");
        oNameSpace.Logon(null, null, true, true);
        oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
        Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
        Outlook.Inspector oInspector = oMailItem.GetInspector;
        oInspector.Activate();
        oMailItem.SaveSentMessageFolder = oOutboxFolder;
        if (attachments.Get(context) != "")
        {
            var attachMent = attachments.Get(context).Split(';');
            foreach (var item in attachMent)
            {
                if (item != "")
                {
                    oMailItem.Attachments.Add(@"" + item);
                }
            }
        }
        oMailItem.Body = bodyValue.Get(context);
        oMailItem.To = toValue.Get(context);
        oMailItem.Subject = subjectValue.Get(context);







        //Thread.Sleep(500);
        oMailItem.Display(true);
        oInspector.Activate();
        Thread.Sleep(2000);
        
        SendKeys.SendWait("%s");
     
       

    }

}

}


#2

Any Thought on my above code ……