简体   繁体   中英

How to Send email from Draft using Powershell?

I'm trying to automatically send all email saved, which are available in "Draft" using powershell.I've seen VBA can do, but powershell is the future. Sharing code will help other peer to tweak.

#Send all items in the "Drafts" folder that have a "To" address filled in.

#Setup Outlook
Add-Type -assembly "Microsoft.Office.Interop.Outlook"
$Outlook = New-Object -comobject Outlook.Application
$myOutlook = $Outlook.Application
$myNameSpace = $myOutlook.GetNamespace("MAPI")
$myFolders = $myNameSpace.Folders

#Set Draft Folder.
$myDraftsFolder = $myFolders("rsprebitz@idafoundation.org").Folders("Drafts")

#Loop through all Draft Items

$myDraftsFolder.Items|foreach-object {

  #Check for "To" address and only send if "To" is filled in.
  If ($_.To.trim().length -gt 0) {

    #Send Item
    $_.Send

  }
}

try this

VWP.CS's answer was close but had to make a slight change to get it to work for me:

# Initialize components
  Add-Type -assembly "Microsoft.Office.Interop.Outlook"
  $Outlook = New-Object -comobject Outlook.Application
  $namespace = $Outlook.GetNameSpace("MAPI")

# Set drafts folder
  $myDraftsFolder = $namespace.Folders.Item('yourmailboxname').Folders.Item('Drafts')

# Loop through all Draft Items
  $myDraftsFolder.Items | foreach-object {

    # Check for "To" address and only send if "To" is filled in.
    If ($_.To.trim().length -gt 0) {

      #Send Item
      Write-Verbose "Sending..." -Verbose
      $_.Send()

    }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM