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 8037835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:02:38+00:00 2026-06-05T03:02:38+00:00

I have a problem with the following PowerShelll script: $mail = $outlook.CreateItem(0) $mail.To =

  • 0

I have a problem with the following PowerShelll script:

$mail = $outlook.CreateItem(0) 
$mail.To = "aaa@gmail.com"
$mail.Subject = "PowerShell Test 1"
$mail.Body = "Body..."
$mail.HTMLBody = "This is test!"   
$mail.Attachments.Add("C:\Test.txt")    
$mail.save()

$mail = $outlook.CreateItem(0) 
$mail.To = "aaa@gmail.com"
$mail.Subject = "PowerShell Test 2"
$mail.Body = "Body..."
$mail.HTMLBody = "This is test!"   
$mail.Attachments.Add("C:\Test.txt")    
$mail.save()

When Outlook IS ALREADY STARTED, script works fine – as expected, I get two emails in Drafts folder.

When Outlook IS NOT STARTED, Outlook first asks user for permissions but at the end I get ONLY SECOND email in Drafts, FIRST EMAIL is missing.

Has anyone encountered this problem, any solutions?

  • 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-05T03:02:40+00:00Added an answer on June 5, 2026 at 3:02 am

    I had the same problem as Ocaso where the first email was being sent to the inbox and the second was sent to drafts. I fixed this problem by setting up a session for outlook:

    $outlook = new-object -com outlook.application
    $session = $outlook.Session
    $session.Logon()
    

    The session basically sets up a time period of when an application, outlook in this case, can take in or setup data. By calling session.Logon(), we’re instantiating a session or time period of when outlook can save data/email. The below article does a better job of explaining sessions:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms714451%28v=vs.85%29.aspx

    Thanks

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

Sidebar

Related Questions

I have a problem with following script. It generates a list of places which
I have following problem to be solved in java: Implement class Alkio. Test with
I have the following script in Powershell ISE . cd E:\Data @ xxxx.zip yyyy.zip
I have a problem following from my previous problem . I also have the
have following problem with validate checkbox array. The validation is bypassed, have taken the
I have following problem: in my layout xml I have relative layout in which
I have following problem: I have built a tabbar application with 4 tabs. I
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
Never thought I'd have this problem :) The following snippet of code works in
I have the following problem which ripped my soul for the past 2 weeks:

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.