Вы находитесь на странице: 1из 2

https://www.emailarchitect.net/easendmail/kb/powershell.aspx?

cat=0#send-email-from-
powershell-example

https://www.enmimaquinafunciona.com/pregunta/64467/como-iniciar-powershell-desde-cmd-
por-la-ruta-de-acceso-especifica

https://enavas.blogspot.com/2017/05/ejecutar-script-de-powershell-desde-la.html

https://sobrebits.com/enviar-correo-desde-powershell/

https://myaccount.google.com/lesssecureapps gmail secure

POWER SHELL EJECUTADO DESDE CMD

powershell -command "& 'c:\users\marcia\correo1.ps1' -sender 'efdomadorgmail.com' -address


'efdomador@gmail.com' -name 'Powershell' -body 'prueba del sistema'"
# To use the following codes, please download and install
# https://www.emailarchitect.net/webapp/download/easendmail.exe on your machine

Param(
[string]$sender,
[string]$address,
[string]$name,
[string]$body
)

[reflection.assembly]::LoadFile("C:\Program Files
(x86)\EASendMail\Lib\net20\EASendMail.dll")

function SendMailTo($sender, $name, $address, $subject, $body, $htmlFormat) {

$mail = New-Object EASendMail.SmtpMail("TryIt")


$mail.From.Address = $sender

$recipient = New-Object EASendMail.MailAddress($name, $address)


$mail.To.Add($recipient) > $null

$mail.Subject = $subject
if($htmlFormat) {
$mail.HtmlBody = $body
}
else {
$mail.TextBody = $body
}

# please change server, user, password to yours


$server = New-Object EASendMail.SmtpServer("smtp.gmail.com")
$server.User = "efdomador@gmail.com"
$server.Password = "ed23081979."

# If your 25 port is blocked by ISP, you can try to use 587 port
$server.Port = 587

# Using TryTLS,
# If smtp server supports TLS, then TLS connection is used; otherwise, normal
TCP connection is used.
# https://www.emailarchitect.net/easendmail/sdk/?ct=o_smtpconnecttype
$server.ConnectType = [EASendMail.SmtpConnectType]::ConnectTryTLS

# If your server is Exchange 2007 or later version, you can use EWS protocol.
# https://www.emailarchitect.net/easendmail/sdk/?ct=o_serverprotocol
# Set Exchange Web Service Protocol - EWS - Exchange 2007/2010/2013/2016
# $server.Protocol = [EASendMail.ServerProtocol]::ExchangeEWS

$smtp = New-Object EASendMail.SmtpClient


$smtp.SendMail($server, $mail)
}

function SendMailFromPowerShell () {
#$sender = "efdomador@gmail.com"
#$name = "PowerShell"
#$address = "efdomador@gmail.com"
$subject = "Test email from Powershell"
#$body = "This is a test email from Powershell"

try {
"Start to send email to {0} ..." -f $address
SendMailTo $sender $name $address $subject $body ""
"Email to {0} ha sido enviado!" -f $address
}
catch [System.Exception] {
"Ha fallado el envio de email: {0}" -f $_.Exception.Message
}
}

SendMailFromPowerShell

Вам также может понравиться