send-mail message with vote buttons

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 10 months, 1 week ago.

  • Author
    Posts
  • #34447
    Profile photo of David Schmidtberger
    David Schmidtberger
    Participant

    i've done a lot of googling this morning, and have found using the outlook.application method to do this, however, this won't work when running powershell using authorized accounts as they do not have mailboxes.

    what i need is a way to send these when the account logged into powershell does not have a mailbox.

    i've had to do appointments in the same fashion, but in that case i wound up running a seperate script in a called window asking for different credentials. as this is going into a gui tool, this isn't optimal.

    the only thing that is coming to mind would be to run a script-block as another user, but, not really sure how i could accomplish that

  • #34449
    Profile photo of Don Jones
    Don Jones
    Keymaster

    The voting buttons are an Outlook-specific piece of functionality. I imagine Outlook encodes something into the message to trigger that display, so all I can think of is to send one of those messages to a Gmail account, try to look at the raw message, and see what Outlook's embedding in there. Then you could try and duplicate that using Send-MailMessage.

    This (https://support.microsoft.com/en-us/kb/290809) suggests Microsoft is using TNEF-encoding, which is super-not-common. It's also based on RTF, not HTML, which means actually constructing the message manually is going to be a PITA.

    Further, from what I'm reading, the Voting functionality only works if the sender has an actual mailbox on the server. So if you use Send-MailMessage, you'd need to make sure the Reply-To and Send-As are set to an actual mailbox. That also means your Exchange server is going to have to allow relaying, which it probably doesn't.

    You've got a lot of hurdles in front of you on this one, not because of PowerShell, but because of the way this feature works. Good luck.

  • #34452
    Profile photo of David Schmidtberger
    David Schmidtberger
    Participant

    thanks Don.
    i did find the following code snippets to do this utilizing the outlook.application method: $olComObject = new-object -comobject outlook.application
    $NewMail = $olComObject .CreateItem(0)
    $NewMail.Subject = "Testing Voting Options"
    $HTMLBody = "Please use the attached voting buttons in this email to select the best scripting language!"
    $NewMail.HTMLBody = $HTMLBody
    $NewMail.To = "recipient@domain.com"
    $NewMail.VotingOptions="VBScript;PowerShell;Python;Ruby;Perl"
    $NewMail.Send()

    the issue is the gui will have to be run as an account without a mailbox.
    would you have any quick pointers to executing a code-block fully as another user?

  • #34460
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Do you know their password, and are you willing to have it stored in plain text?

  • #34462
    Profile photo of David Schmidtberger
    David Schmidtberger
    Participant

    well, i can add userid/pw masked text boxes in the gui and have the users input that value

    thats where i was starting, but, couldn't wrap my head around calling just that specific code to be fully run as another user

  • #34463
    Profile photo of Don Jones
    Don Jones
    Keymaster

    OK, well in that case you probably do it. Just use Get-Credential to prompt for the credential, and use Start-Job to pass the script block and the credential. Or, put the necessary code in a separate script, and run it with Start-Process, which also accepts a credential.

You must be logged in to reply to this topic.