Arquivo

Archive for maio \20\UTC 2016

Power Shell – Script para enviar e-mail

Prezados,

Segue o script em Power Shell para enviar e-mail autenticado:

Obs.Basta salvar com extensão “*.ps1”

$SMTPServer = “smtp.xxx.com.br”
$SMTPPort = “587”
$Username = “alerta@xxx.com.br”
$Password = “sua-senha”

$to = “alerta@xxx.com.br”
$cc = “suporte@xxxxx.com.br”
$subject = “Teste Felipe”
$body = “Teste de Backup”
$attachment = “c:\Temp\texto.txt”

$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.body = $body
$message.to.add($to)
$message.cc.add($cc)
$message.from = $username
$message.attachments.add($attachment)

$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message)
write-host “Mail Sent”

Felipe Gabriel
MCP + MCDST + MCSA + MCTS
Microsoft Community Contributor Award
Blog: Felipegbass.wordpress.com
Twitter: @felipegbass

 

 

Anúncios