Pobranie adresu email z wiadomości w formacie SMTP

26 March 2015

function GetSenderSMTPAddress([object] $mail)

{

    $PR_SMTP_ADDRESS =  "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"

    if (!$mail)

    {

        $URL_Format_Error = "email object empty throw execption"

       Write-Error $URL_Format_Error

    }Po

    if ($mail.SenderEmailType -eq "EX")

    {

        $sender = $mail.Sender

        if  (-not (!$sender))

        {

            #Now we have an AddressEntry representing the Sender

            if (($sender.AddressEntryUserType -eq 0) -or ($sender.AddressEntryUserType -eq 5))

            {

                #Use the ExchangeUser object PrimarySMTPAddress

              $exchUser = $sender.GetExchangeUser()

                if (-not (!$exchUser))

                {

                    return $exchUser.PrimarySmtpAddress

                }

                else

                {

                    return "unknow@address"

                }

            }

            else

            {

                 

                return $($sender.PropertyAccessor.GetProperty($PR_SMTP_ADDRESS))

            }

        }

        else

        {

            return "unknow@address"

        }

    }

    else

    {

        return $mail.SenderEmailAddress

    }

}


Kategorie: Power Shell