Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7874397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:47:56+00:00 2026-06-03T02:47:56+00:00

I want to create a file, email it as an attachment, then delete the

  • 0

I want to create a file, email it as an attachment, then delete the file, using JScript.

The problem lies in the fact that deleting the file too soon will prevent Outlook from attaching the file to the email.

I will be creating a MailItem and displaying it with something like the following code. The email will not automatically be sent, but it will be displayed so the user can edit it if necessary.

var outlook = new ActiveXObject("Outlook.Application");
var msg = outlook.CreateItem(0);
msg.Recipients.Add(toAddress);
msg.Subject = subject;
msg.htmlbody = body;
msg.Attachments.Add(attachment);
msg.Display();

My question is, when is it safe to delete the attachment file? I know MailItem has events, where I could maybe delete the attachment file in the AttachmentAdd event. But, AFAIK, there is no way to subscribe to ActiveXObject events in JScript.

My thoughts:

  • I could delete the file immediately, if Attachments.Add is synchronous (or if Display waits until all attachments have been read)
  • I could sleep for x seconds, and then delete the file.
  • Maybe there is a way to subscribe to an event, and I haven’t found it.

Details:

This script is, for all intents and purposes, running in wscript.

This is not specific to any Outlook version. It should work with any version.

I will also be attaching several other files to the email.

If you have questions, just ask.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:47:56+00:00Added an answer on June 3, 2026 at 2:47 am

    I tried the following code and it worked.

    var fso = new ActiveXObject("Scripting.FileSystemObject");
    
    var outlook = new ActiveXObject("Outlook.Application");
    var msg = outlook.CreateItem(0);
    msg.Subject = "Subject";
    msg.Body = "Body";
    msg.Attachments.Add(file);
    fso.DeleteFile(file); // No problems.
    msg.Display();
    

    It isn’t mentioned anywhere in the documentation, but Attachments.Add() seems to be synchronous.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create one application which send email with attachment(select file from SD
I want to email a PDF as an attachment that was created using FPDF.
I want to create log file for my flex application. That is the file
Using C# and WinForms in VS2008, I want to create a file browser control
I want to create this parameter file so that I can send it to
I want to create a CustomAction C# DLL file that depends on a third-party
I want to create an e-mail file on a web server that will open
I’m trying to create a VBA macro that saves an email attachment to folder
I want to create a file in the current directory (where the executable is
I want to create a PNG file from a System.Drawing.Bitmap with the colours defined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.