0% found this document useful (0 votes)
135 views2 pages

Configurar Correo Con Powershell

This document provides an example script to send an email from PowerShell using the EASendMail library. The script defines a SendMailTo function that creates an email object, sets the from, to, subject, and body properties, and uses an SmtpClient to send the email through a specified SMTP server. It then calls this function from the SendMailFromPowerShell function to send a test email to the defined address. Running the PowerShell script from the command line allows automating email sending directly from the OS.

Uploaded by

Ender Domador
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views2 pages

Configurar Correo Con Powershell

This document provides an example script to send an email from PowerShell using the EASendMail library. The script defines a SendMailTo function that creates an email object, sets the from, to, subject, and body properties, and uses an SmtpClient to send the email through a specified SMTP server. It then calls this function from the SendMailFromPowerShell function to send a test email to the defined address. Running the PowerShell script from the command line allows automating email sending directly from the OS.

Uploaded by

Ender Domador
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 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


'[email protected]' -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 = "[email protected]"
$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 = "[email protected]"
#$name = "PowerShell"
#$address = "[email protected]"
$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

You might also like