Create Outlook email draft using PowerShell

后端 未结 5 1661
清酒与你
清酒与你 2020-12-03 07:43

I\'m creating a PowerShell script to automate a process at work. This process requires an email to be filled in and sent to someone else. The email will always roughly fol

5条回答
  •  离开以前
    2020-12-03 08:34

    $olFolderDrafts = 16
    $ol = New-Object -comObject Outlook.Application 
    $ns = $ol.GetNameSpace("MAPI")
    
    # call the save method yo dave the email in the drafts folder
    $mail = $ol.CreateItem(0)
    $null = $Mail.Recipients.Add("XXX@YYY.ZZZ")  
    $Mail.Subject = "PS1 Script TestMail"  
    $Mail.Body = "  Test Mail  "
    $Mail.save()
    
    # get it back from drafts and update the body
    $drafts = $ns.GetDefaultFolder($olFolderDrafts)
    $draft = $drafts.Items | where {$_.subject -eq 'PS1 Script TestMail'}
    $draft.body += "`n foo bar"
    $draft.save()
    
    # send the message
    #$draft.Send()
    

提交回复
热议问题