Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict voting button to 'To' address and not send to 'Cc' in outlook via powershell?

Powershell Script[script1.ps1] -:

param(
[string]$username,
[string]$username1,
)

$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)

$Mail.To = "$username1"
$Mail.Cc = "$username"
$Mail.Subject = "SUBJECT"
$Mail.Body = "--content--"


$mail.VotingOptions = "Approve;Reject"

$Mail.Send()

Php Code -:

<?php
  $connection = oci_connect("username","password","db_name");
  $lname = $_SESSION['lead_name'];
  $main_query=oci_parse($connection,"SELECT * FROM TABLE WHERE FIELD= '$lname'");
  oci_execute($main_query,OCI_DEFAULT);
  while($res = oci_fetch_array($main_query)) 
      {
        $mail= $res['USERNAME'];        
      } 
      $_SESSION['mail_id']=$mail;
      $cc = $_SESSION['mail'];

      $username = $cc;
      $username1 = $_SESSION['mail_id'];

    $psScriptPath = "C:\\xampp\\htdocs\\Website_LMS\\Powershell\\script1.ps1";
    $query = shell_exec("powershell -command $psScriptPath -username '$username'< NUL -username1 '$username1'< NUL");
      oci_close($connection);
  ?>

Powershell Script is used to send email to outlook. All these parameters username,username1 are sent from php script via shell exec command. These two are email address.

Now i want to use the voting button to approve or reject a leave which is triggered to the email addresses menetioned. I want the voting button is sent to username1 only i.e "To" addresses and not to "cc" addresses. I want to implement this via powershell.

like image 752
Rocker Rocky Avatar asked Oct 31 '22 02:10

Rocker Rocky


1 Answers

Since the voting buttons (= the information on what to vote) are part of the mail, like the text and the subject, it is not possible to just make them visible to some of the recipients. Outlook (or better, the server, most likely Exchange) will send the very same email to all recipients, regardless whether they are addressed via To, Cc or Bcc.

That's by design, as stated in RFC2822 (Internet Message Format):

The destination fields specify the recipients of the message. Each destination field may have one or more addresses, and each of the addresses indicate the intended recipients of the message. The only difference between the three fields is how each is used.

You can simply send two Mails with the same content, except for the buttons:

param(
[string]$username,
[string]$username1,
)

$Outlook = New-Object -ComObject Outlook.Application
$Mail1 = $Outlook.CreateItem(0)
$Mail2 = $Outlook.CreateItem(0)

$Mail1.To = "$username1"
$Mail2.To = "$username"
$Mail1.Subject = "SUBJECT"
$Mail1.Body = "--content--"
$Mail2.Subject = "SUBJECT"
$Mail2.Body = "--content--"


$mail1.VotingOptions = "Approve;Reject"

$Mail1.Send()
$Mail2.Send()

To clear things up for the recipients, you could add a text to the mails, stating that this mail is also sent to $username.

like image 186
Marc Avatar answered Nov 15 '22 06:11

Marc