本文共 2575 字,大约阅读时间需要 8 分钟。
Send-mail.ps1 –mailboxname <邮箱名>
param
(
[string]$mailboxname
)
function sendmail($mailaddr){
$msg=New-Object System.Net.Mail.MailMessage
$msg.To.Add($mailaddr)#收件人
$msg.From = New-Object System.Net.Mail.MailAddress("Helpdesk@canway.com", "邮箱助手",[system.Text.Encoding]::GetEncoding("GB2312")) #发件人
$msg.Subject = "Welcome to canway"#邮件主题
$msg.SubjectEncoding = [system.Text.Encoding]::GetEncoding("GB2312")
$msg.Body ="你好,欢迎使用canway邮箱"#邮件正文
#$Attachments=New-Object System.Net.Mail.Attachment("D:\Documents\xxxx.zip")#创建附件
#$msg.Attachments.add($Attachments) #添加附件
$msg.BodyEncoding = [system.Text.Encoding]::GetEncoding("GB2312")
$msg.IsBodyHtml = $false#发送html格式邮件
#$msg.Priority = [System.Net.Mail.MailPriority]::High#邮件等级
$client = New-Object System.Net.Mail.SmtpClient("192.168.0.3")#一般是HUB服务器或者是内部SMTP gateway
$client.UseDefaultCredentials = $false
$client.Credentials=New-Object System.Net.NetworkCredential("Helpdesk@canway.com", "1qaz@WSX")#服务器的访问凭据
try {$client.Send($msg)}
catch [Exception]{$($_.Exception.Message) $mailaddr } }
$mailaddr = $mailboxname
sendmail $mailaddr
<?xml version="1.0" encoding="utf-8" ?>
<Configuration version="1.0">
if($succeeded) {
start-sleep -s 10
Set-ADServerSettings -ViewEntireForest $true
$Alias = $provisioningHandler.UserSpecifiedParameters["Alias"]
$newmailbox=$Alias +"@"+"canway.com"
C:\temp\send-mail.ps1 -mailboxname $newmailbox
Set-CASMailbox $newmailbox -IMAPEnabled $false -POPEnabled $false
}
</Configuration>
Enable-CmdletExtensionAgent "Scripting Agent"
New-Mailbox -Name 'user11' -Alias 'user11' -OrganizationalUnit 'canway.com/Test' -UserPrincipalName 'user11@canway.com' -SamAccountName 'user11' -FirstName 'user11' -Initials '' -LastName '' -Password 'System.Security.SecureString' -ResetPasswordOnNextLogon $false -Database 'MailboxDatabase01'
Enable-Mailbox -Identity 'canway.com/Test/user10' -Alias 'user10' -Database 'MailboxDatabase01'
转载于:https://blog.51cto.com/11258494/2139413