Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This code works on my system with Outlook 2010 to send an email with no user interaction. It's <em>slightly</em> brittle, in that, if the user happens to be actively working on the system (typing, clicking) when the mail is composed, it could occur that user input makes its way into the window that pops up for a split second, and either interfere with the sending of the mail, or add extra unknown characters into the body of the mail.</p> <p>As long as the user on whose system this is running is aware of this, and the potential consequences of spurious keystroke interference are not business-critical, this function is acceptable.</p> <p>Important to note: the key to this solution is that we do not call the <code>MailItem.Send</code> method. This is the method that triggers the programmatic access protection. Instead, we trigger the <kbd>ALT</kbd>+<kbd>s</kbd> shortcut, which by default, when a mail window has focus in Outlook, presses the "Send" button. If you have the default spell checking prompt enabled, this will pop up a further prompt for spellchecking. Our solution was to disable the spellchecking prompt, although I'm sure you could add some more SendKeys to click through it, since the spellchecking prompt is not a security-related dialog.</p> <p><em>A note about UIPI (User Interface Privilege Isolation):</em></p> <p>Outlook 2010 runs as the user who logged into the system, with a <strong>Medium</strong> integrity level. Programs which are launched by Windows Explorer, or started as a child or descendant of a program which was launched in a similar way, will also be launched with a <strong>Medium</strong> integrity level. UIPI is not effective at preventing "SendKeys" type input, as long as the user and session ID match, and the integrity level is the same or higher. In my particular environment, the user and session ID are identical, and the integrity level is the same for the VBScript host process and the Outlook process. In your environment, if any of these conditions are false, this code will <strong>not</strong> work. It is also untested on earlier or later versions of Office than version 2010.</p> <pre><code>Sub SendEmail_Outlook() Set WshShell = WScript.CreateObject("WScript.Shell") Set ol=CreateObject("Outlook.Application") Set Mail=ol.CreateItem(0) Mail.to= "you@example.com" Mail.Subject = "test" Mail.HTMLBody = "test" Mail.Display WshShell.SendKeys "%s" Set Mail = Nothing Set ol = Nothing End Sub SendEmail_Outlook </code></pre> <p>Also, here is how to make this work when running the VBScript from Windows Task Scheduler. Just tick the box depicted by the red oval, "Run With Highest Privileges", to make it run with the highest possible integrity level without UAC elevation ("Medium" if you are not an administrator account).</p> <p><img src="https://i.stack.imgur.com/KM3AN.png" alt="windows task scheduler properties"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload