Deleting pfd files after sending as mail attachments - batch-processing

I know its kind of repeated question but m getting an error message as 'File cannot be accessed as it is being used by other process'. When I run my exe through a batch process.
On running the exe directly in the remote server, I donot get any such error but batch process causes this to happen. The batch process goes into an infinite loop and never ends. even though the exe functions properly. Reports are created and I recieve them as mail attachment.
M using smtpclient to send mails. I ahve also used MailMessage.Attachments.Dispose() and MailMessage.Dispose() to kill the attachment objects.

I got the correct way.
I was disposing the mailmessage object first and then the attachment object.
Just had to reverse the order and it worked perfectly!
Thanks!

Related

COM Add-In > Dispose objects correctly

In an Outlook Add-In, objects seem to be kept in memory. As a result when the Add-In is active in Outlook, .eml files can only be opened once. When trying a second time, I get:
We can't open [filename]. It's possible the file is already open, or you don't have permission to open it ...
When the Add-In is disabled, .eml files can be opened multiple times without any issue.
In Add-In code, I placed a Marshal.FinalReleaseComObject(obj) at multiple places but it did not help. The code is fairly long and spread of over multiple files. It might be that I missed a release.
Is there any way to easily troubleshoot the situation and identify the root cause.
Try to comment out most of your code and bring it back a few lines at a time until the problem comes back.
As a sledgehammer solution, try to call GC.Collect() after you are done.

Saving outlook email attachment to disk to enable reading of file content by strings.exe or exiftool.exe safe?

I am using strings.exe https://learn.microsoft.com/en-us/sysinternals/downloads/strings and
exiftool.exe
to try and establish whether the outlook attachments are the file type that they are listed and just haven't changed their extension
Problem is that both of these tool expect a filepath which would force me to use .SaveAsFile(string path) on the mail item attachment object and save to disk to scan them before I delete them
Is this a security risk?
As far as I know I am not executing the file simply reading its metadata and therefore any malicious files should not be executed right?
I am using this wrapper to read the file from c# https://github.com/AerisG222/NExifTool
I have bitdefender installed on the machine and I know I have tried to save a test virus file and it immediately picked it up and deleted it
I have had a look at redemption and it has an option to return AsStream which would allow to use in memory but to scan with exiftools.exe and strings.exe they are both expecting a filepath
hoping to get answer before so-police comes
It will not be a security risk. The file is never executed.
More than that, OOM blocks certain attachment types (such as exe) - they are not even accessible in the MailItem.Attachments collection (unless you are using Redemption of course).

Mozilla Thunderbird: recovering emails from global-messages-db.sqlite

How can I recover lost emails from Thunderbird's global-messages-db.sqlite?
My PC kernel panicked in the middle of migrating some emails from Imap to local storage. As a result, that migration did not complete writing to disk.
Due to the failed migration, many emails exist in global-messages-db.sqlite but do not exist in corresponding mbox files (eg not in Mail/username#hostname.tld). I verified that the emails exist in global-messages-db.sqlite via sqlitebrowser. In fact, I've successfully manually extracted the content of some critical messages.
Upon startup, Thunderbird is culling from global-messages-db.sqlite emails it does not find in mbox files. If I replace the active global-messages-db.sqlite with a version containing my lost emails, Thunderbird ignores and eventually removes those lost emails.
This would be a trivial dilemma if I still had access to the Imap account. Unfortunately, I do not.
Scripting a converter is trivial
I would quickly code a gloda->mbox converter, that's probably your fastest path to success. You've already discovered the structure of the gloda database. Now, it's just a matter of writing a little JavaScript in node.js that opens an sqlite database, iterates over the folders, then the messages in each folder, and writes an mbox file for each folder. The mbox file format is trivial (just pay attention for "From"). Once you have that, you can open these mbox files in Thunderbird by just overwriting an existing empty Local Folder.
P.S. Just as a reminder: Make backups. Esp. before such migration operations, but also regularly.

Outlook VBA loading a saved file from HD

I've found quite a bit on how to automate saving emails and attachments from Outlook to drive locations, but I'm lost on how to access and manipulate those objects that are now saved. So, as an example, I have a folder on my desktop ('C:\Desktop\emails\') with about 1000 emails, and I need to pull the attachments from each of them. The process of extracting attachments in an iterated method is well documented, I'm just stuck on how to actually specify that folder and use it.
Are the MSG files? Use Application.Session.OpenSharedItem to open each MSG file and get back the MailItem object.

How kill a specific process

I have a process that interacts with an Excel application in background, but sometimes the process has an error and the Excel Application doesn't finish correctly.
Always, when this process starts try to delete the Excel file from the hard drive.
But, when the process has an issue and I retry to run the process again, the following message shows me when I try to delete the Excel file:
"The process cannot access the file [Excel file path] because it is being used by another process."
I can not kill all processes of Excel.
Then, my question is:
Is there some way to know what is the process that manage this Excel?
Or, Is there some way to know the process using a Try ... Catch structure?