Type into types half text then deletes it then types the rest, why?

Exactly what I put in the title.

I use type into activity on default settings, to type into a box in Outlook 2016 (file dialog to attach a pdf to an email).
Before type the robot selects the folder, its always the same (that works fine, few clicks on the left panel).

Then it start typing “Service” then suddenly deletes the word “Service” in the middle of typing (I even saw it goes blue color like when text is selected). then it keeps typing the remaining of the string " Summary.pdf" … then the link is not working cos the file path does not exist.

image

note: it is 20.4.5 version of studio, and “upgrading” is not an option.

@Robert_Lovasz

First of all for doing outlook activities we have UiPath.mail.activities package which has outlook related activities

But even then you want to use ui the try windows messages option in the type into properties

Cheers

UiPath does not support the .msg format so I can’t use it’s “activities”.
I need to use Outlook app.
I tried all options, windows message, simulate type. Nothing worked.
My next idea is to use the clipboard send my message to clipboard and and send “ctrl+v” that’s what I’m gonna test next.

I can’t accept that answer, because 1) its not addressing my question, “why” it happens. it only tries to give “what to do” that does not work (I already tried).

I need to use the UI (Outlook app) unless you have an other way to do these steps in version 20.4.5 studio:

  1. first open an Outlook template (in Outlook),
    I added the file to user templates, so it’s a few click to open
  2. add an attachment (this is what failed here about 50% of times yesterday, typing in the file name fully)
  3. save the email as .msg (Outlook) format (which is by my search on forum “NOT supported” by UiPath, all I find is suggestions to save as .eml but I don’t need suggestions how to do the job other way I need to do it this way, its not my choice)

note: last week it ran perfectly, next week it may run again perfectly… I may never see this behaviour again, maybe the network was slow, my VM was slow, I don’t know. But the pop-ups that came with the error were really annoying even as Human I had hard time to “close” them, they needed multiple clicks to get closed…

The only activities I see is, I don’t know which one supposed to open a template, add attachment, then save it… I guess none:
image

@Robert_Lovasz

Okay so if you want to save as .msg then yes outlook activities might not help…you can try writing a vb.net code to save like that

Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg = (Outlook.MailItem)oApp.Session.OpenSharedItem("C:\MyCustomMsg.msg");

 Outlook.Attachments oAttachments = oMsg.Attachments;

 for (int i = oAttachments.Count; i > 0; i--)
        {
            Outlook.Attachment oAttachment = oAttachments[i];
            // Check if the attachment matches the desired file name
            if (oAttachment.FileName.Equals("attachment.pdf"))
            {
                string tempFilePath = "C:\attachment_temp.pdf";
                oAttachment.SaveAsFile(tempFilePath);

                oAttachment.Delete();

                oAttachments.Add(tempFilePath, Outlook.OlAttachmentType.olByValue, 1, "attachment.pdf");

          
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oAttachment);
            }
        }

       oMsg.SaveAs("C:\MyCustomMsg_Edited.msg", Outlook.OlSaveAsType.olMSG);

      System.Runtime.InteropServices.Marshal.ReleaseComObject(oAttachments);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oMsg);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oApp);

This is a sample code using vb.net you can modify as per your need …rather than front end

Cheers

This looks promising, let me study that code for a sec :smiley:

You may help me with this or some1 good with VB. I probably could figure it out thou…
all i need is

  1. I got path to a Template file (as .msg file)
  2. I need to add an email into the “TO” field
    and an attachment (PDF file) I also have the path for that.
  3. save it to a special folder (I have the full path to it) already in variable.

Only 1 attachment (so I guess I don’t need any foreach), 1 adressee (TO), and save it again as .msg to a different.
I may need to make a copy of the template first to the new folder (with the new name), then I just have 2 steps. Add addressee and attach the file. (the file also will be always same, as it is deleted after/before it is created).

So basically I create a PDF file with password to each ‘customer’, attach it to the email (after that delete, but in case next time I check if file exists, if and ‘try’ delete again if it was left there for some reason).

So I need just this 2 step,

  1. attach a PDF to an .msg file
  2. add addressee and “save it” .

It’s always 1 attachment, 1 addressee. Two steps only.

@Robert_Lovasz

Then from the code I am already opening and saving and have a loop for attachments…now you can rrmove the loop and have thw add attachment directly

For email to change …you can get the to field property and modify

oMsg.To.Add(New System.Net.Mail.MailAddress("someone@domain.com"))

Cheers

I just figuring out even the basics… So this is how I pass my variables yep?

Am I correct the arguments I just do like this, then I can use them in the code as they were variables?

and then I need to uses this two variable, for the .msg file and for the PDF I attach, and the sender and and addressee do I need both? I can hard code those both no issue, or use variable later, whatever.

@Robert_Lovasz

Exactly…you can create arguments fas in and out whichever you need…then use them as variables…

Basically I gave hardcoded dummy paths…you can add variables there and pass the data to arguments created in invoke code

To mail adress also will be argument

Cheers

unfortunately your code only gives a million errors, starting with ‘Outlook’ is not declared. I also don’t understand why you put ; to end of al line if it is VB code, aren’t you mixing c# with vb ?

I tried in C# … I’m m ore familiar with it that VB … even this line won’t “pass” (this came up as result of my search, but it wont work

Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();

I’m getting an error:
Cannot find the interop type that matches the embedded interop type ‘Microsoft.Office.Interop.Outlook.Application’. Are you missing an assembly reference? At line -30

I may have found a package that would work for me but I am not 100% about these licensing things. Is this package free to use? On their website there are some big prices if you use them, but that is only if you use it in the cloud isn’t it?

Is this free to use in UiPath?

Now I can start work with your code, after 2 hours if failing, I figured that I need to install the Microsoft.Office.Interop package, which you forgot to mention, I never knew that, luckily I figured it out. :smiley: I haven’t code in ages, normally I don’t use “studio” a lot, just do some code challenges on websites like codewars :smiley: I forgot that I may need to install that package to use it

everything works so far, this last line gives me error
it expects ) after New System for some reason…
image

shouldn’t this be something like
oMsg.To.Set( ) … ?

@Robert_Lovasz

Can you give me the code which you wrote…I wrote whole Of the code on the go…sorry for that…I can fic and compile and give you the exact one

And really appreciate you taking time in fixing it…I shpuld have compiled before pasting here

Cheers

I accept this because it helped me to find solution, thou. I had to do like 2 hours of research still on the stuff. Some of your code didn’t work for me, after I installed package I still needed to use the full path to the objects I couldn’t use aliases for namespace (using didn’t work) for me.

I did not use everything from your code I don’t need to check other attachments, because I always start with a template that has no attachments, and the file I create is always deleted If exist prior to this code running.

Also one little note that oMsg.To doesn’t have any methods no “Add” it’s just have constructor set/get, after digging I figured you simply use it as a variable, and for some reason System.Net.Mail.MailAddress …that didn;'t work for me, I simply did this line to add email as string:

oMsg.To = “email@blabla.com”;

It worked when I open in Outlook address is there, I have to check that if it works correctly (when I send), maybe I need to format it later with your code and I need to find why it didn’t work for me, but “Add” is not working. (I don’t know if studio version matters when you use .Net code)

As I also mentioned, you referred to “vb.net” but you wrote c# code, I’d like to mention that to prevent some confusion. Yes .NET is pretty similar, but your code is c# not VB.

I still accepted your solution, it mostly worked after I fully typed in the lines.

Since topic is closed I can just edit this message to put the solition “fixed” as you requested, I’ll just drop some screenshots:

Arguments:
image

Code:

//Creating Office object with name oApp
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();

//Creating email Item object with the name oMsg
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

//Assign the template message file to the oMsg object, casting type too
oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.Session.OpenSharedItem(in_TemplatePath);

//Create attachments object (assigning the ponter from oMsg)
Microsoft.Office.Interop.Outlook.Attachments oAtts = oMsg.Attachments;

//Add the attachment with path and name
oAtts.Add(in_AttachmentPath,Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue,1,in_AttachmentName);

//assign Addressee (oMsg.To has constructor so it can be just used similar  to a varible in programming.
oMsg.To = in_To;

//saving email
oMsg.SaveAs(in_SavePath);

//deleting email from Outlook
oMsg.Delete();

//Free all objects from memory
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAtts);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oMsg);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oApp);

I also commented all lines in case someone in future (with less programming knowledge) need to look at it later, for some reason namespaces didn’t work for me so I also had to fully type in all method names and properties… I use old 20.4 version studio for this…

1 Like

@Robert_Lovasz

I agree…while writing I combined both together…ahpuld have been more cautious and yes shpuld never write a code directly on phone…I should use an ide here as well or else …:melting_face:….

Hope it atleast gave you a way…if any issues let us know…we can try checking on the methods as well…

I wrote the code just by remmebering whatever i wrote for previous rwquirements…so few might be messed up as well…as no hints were taken while writing it

And if you can post the corrected code you are using …that might help others in redoing it and may be you can mark that as solution as well…

Cheers

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.