Remove email attachment of excel from outlook email and add new excel attachment

How can I remove old excel attachment of and forward that email with new excel attachment how can I do it any activities in uipath?? @Palaniyappan

Hi @Suresh_reddy2
Did u mean to update the attachment and forward the same mail right?

I should remove the old excel attachment and add new updated excel attachment

Well I think instead of concept of forwarding the mail with new attachment

Can u try like this

Adding the subject same as of previous mail (with prefix as FW:) needed.

Adding the same body as the mail and other things as well

Adding the attachment too

Regards

Nived N :robot:

1 Like

For every mail subject and body changes and here the issue is with how to remove email attachment do you any vb code or any other activity

Hi @Suresh_reddy2

Yes it’s seems to be possible by doing the following methods

  1. Delete the attachment

  2. Adding the required attachment again

For that try this

Use this code in invoke code (C#)

msg.Attachments.Remove(msg.Attachments(0))

string file = file_path
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
    // Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
    // Add the file attachment to this email message.
msg.Attachments.Add(data);


Here arguments needed to pass to the invoke code

msg : mail message object (in/out)

file_path : file path of attachment file path (in)

After this use send Outlook mail activity to forward the mail by using forward option

Try this

Hope it helps

Mark it as solution if it helps you

Regards

Nived N :robot:

Hi, I tried up-to removing attachments It’s not removing mail attachments

Hi @Suresh_reddy2

Is that throwing any errors ?

No not throwing any errors

Hi @Suresh_reddy2
Sorry for late response

Actually I tried the invoke code for c# by using below code

item.Attachments.RemoveAt(0);
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(data);
item.Attachments.Add(attachment);

where arguments are

Here I passed data as filename to be added, in my case it is result.csv

and when I run this , it worked perfectly fine…

Instead of file I added while sending the mail, it changed it to result.csv file data

Check this please

Regards,
Nived N
Happy Automation

Hi,Showing errors semicolon and without semicolon also not working properly

Hi, Can you pls share xaml file if you have that
It will help me to under better

Hi did u use the same code ? As I shared in above reply?

Also select the language type as c#

Hi @Suresh_reddy2
sharing a sample file
Main.xaml (13.3 KB)

Regards,
Nived N

Getting assembly reference errors for your workflow can you pls look at the screenshot attached suggest a solution

Can u check the dependencies section and see whether you can repair it

Hi, Dependencies are updated No error was there