2016-12-11 1 views
0

우리는 하나의 이메일 계정으로 Outlook을 이메일로 보내지 만 다른 Outlook 계정으로 보낸 사람의 이메일 주소를 설정할 수있는 방법을 찾고 있습니다. 우리는에 액세스 할 수 있습니다.Powershell, outlook을 다른 이메일로 보내십시오.

나는 인터넷 검색을 시도하고 여기를 둘러 보았고 그럴 수있는 방법을 찾지 못하는 것 같습니다.

여기에 우리가 사용하는 코드가 있습니다.

$Outlook = New-Object -comObject Outlook.Application 
$Mail = $Outlook.CreateItem(0) 
start-sleep 5 
$Mail.subject = "" 
$mail. 
$Mail.To = "" 
$Mail.Cc = "" 
$Mail.Body = "Test" 
$Mail.Display() 
$Mail.Send() 

답변

1

아래의 Outlook 기능을 사용하여 이메일을 보내주십시오. 당신은 실제로저기서 똑같이하고 있습니다. 오류가 있습니까? 어쨌든, 아래 하나를 사용하십시오 : 참조를 위해 함수의 모든 주석을 따르십시오.

Function Global:Send-Email { 
[cmdletbinding()] 
Param (
[Parameter(Mandatory=$False,Position=0)] 
[String]$Address = "[email protected]", 
[Parameter(Mandatory=$False,Position=1)] 
[String]$Subject = "Mail Subject", 
[Parameter(Mandatory=$False,Position=2)] 
[String]$Body = "MailBody" 
    ) 
Begin { 
Clear-Host 
# Add-Type -assembly "Microsoft.Office.Interop.Outlook" 
    } 
Process { 
# Create an instance Microsoft Outlook 
$Outlook = New-Object -ComObject Outlook.Application 
$Mail = $Outlook.CreateItem(0) 
$Mail.To = "$Address" 
$Mail.Subject = $Subject 
$Mail.Body =$Body 
# $Mail.HTMLBody = "HTML BODY" 
# $File = "D:\CP\timetable.pdf" 
# $Mail.Attachments.Add($File) 
$Mail.Send() 
     } # End of Process section 
End { 
# Section to prevent error message in Outlook 
$Outlook.Quit() 
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Outlook) 
$Outlook = $null 
    } # End of End section! 
} # End of function 

# Example of using this function 
Send-Email #-Address [email protected] 

: 당신이 누군가를 대신하여 이메일을 보낼 경우 당신은 다른 사람을 대신하여 메일을 보낼 수있는 권한이 있어야 커넥터 또는 사용자로부터 익명의 메일을 활성화해야합니다. 이 경우, 당신은 참조로 Gmail에에서 메일을 보낼 수

$ mail.From = ""

샘플 예로서 또 하나의 객체를 추가 할 수 있습니다.

$From = "[email protected]" 
$To = "[email protected]" 
$Cc = "[email protected]" 
$Attachment = "C:\temp\Some random file.txt" 
$Subject = "Email Subject" 
$Body = "Insert body text here" 
$SMTPServer = "smtp.gmail.com" 
$SMTPPort = "587" 
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject ` 
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl ` 
-Credential (Get-Credential) -Attachments $Attachment 

... 희망이 도움이
관련 문제