Reply email powershell

旧城冷巷雨未停 提交于 2021-02-11 13:21:21

问题


Hi again StackOverflow's comunity, I will ask about method ".reply()". This is the code I am trying:

function Unread ($correo) {
    if(($correo -eq $null) -or ($correo.Unread.ToString() -like "False")){
        $Noleido = $false
    }else{  
        $Noleido = $true
     return $Noleido
    }
}

    $body = "Bla bla bla"
    $firma = "I am here"
    #$cuerpo = "A test ps"
    $subject = "Re: automated reply"
    $Outlook = New-Object -comObject Outlook.Application 
    $OutlookFolders = $Outlook.Session.Folders.Item($buzon1).Folders
    #Map la bandeja de entrada.
    $bandeja_de_entrada=$OutlookFolders.Item("INBOX_FOLDER")

    #Creamos el objeto que hace referencia a la bandeja de entrada y los mensajes que contiene.
    $all_mail=$bandeja_de_entrada.Items


foreach ($mail in $all_mail){ 
    $flag1 = Unread($mail)
    if($flag1 -eq $true){     
       #$mail.to = ""         
       $mail.body =" $cuerpo" +"$firma"
       $mail.subject = $subject
       $mail.reply()
   }
}

Dont send the email.

Its solved in a answer


回答1:


The method reply creates a MailItem prepopulated with the necessary properties based on the original mail.

If you save the MailItem created by the reply method to a variable you can then use the method send to actually send the reply.

Modifying your script to look something like the following would probably work.

$body = "Bla bla bla"
    $firma = "I am here"
    $subject = "A test ps"
    $Outlook = New-Object -comObject Outlook.Application 
    $OutlookFolders = $Outlook.Session.Folders.Item($buzon1).Folders
    #Map la bandeja de entrada.
    $bandeja_de_entrada=$OutlookFolders.Item("INBOX_FOLDER")

    #Creamos el objeto que hace referencia a la bandeja de entrada y los mensajes que contiene.
    $all_mail=$bandeja_de_entrada.Items

    foreach ($mail in $all_mail){      
       #$mail.to = ""
       $reply = $mail.reply()
       $reply.body = " $cuerpo $firma"
       $reply.subject = $subject
       $reply.send()
    }

If you want to include the original message instead of overwriting it you could change the $reply.body-line to something like this;

$reply.body = $reply.body + " $cuerpo $firma"


来源:https://stackoverflow.com/questions/53317181/reply-email-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!