-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSend-Email.ps1
More file actions
47 lines (44 loc) · 1.66 KB
/
Send-Email.ps1
File metadata and controls
47 lines (44 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Send-Email {
<#
.SYNOPSIS
Envia un correo via Gmail
.DESCRIPTION
Enviar correo desde gmail, requiere tener activado el acceso a aplicaciones menos seguras: https://www.google.com/settings/security/lesssecureapps
.EXAMPLE
Send-Email -From Hola@Mundo.com -Password !P4ss -To Hello@World.com -Subject Ejemplo -Body "Hey!`nEsto es una prueba" -Attachment C:\prueba.txt
.LINK
https://www.patreon.com/HelloWorldYT
https://www.facebook.com/HolaMundo.YT
https://twitter.com/H3LL0WORLD
https://www.youtube.com/channel/UCN1R36uVmYCnfKj-1YTSivA
#>
param (
[String] $From,
[String] $Password,
[String] $SecurePassword,
[String] $To,
[String] $Subject,
[String] $Body=' ',
[String] $Attachment
)
if ($host.version -eq "2.0") {
$SMTPClient = New-Object Net.Mail.SmtpClient("smtp.gmail.com", 587)
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($From,$Password)
$SMTPClient.EnableSsl = $True
$SMTPClient.Send($From, $To, $Subject, $Body)
} else {
if ($Password) {
$Passwd = ConvertTo-SecureString $Password -AsPlainText -Force
} elseif ($SecurePassword) {
$Passwd = ConvertTo-SecureString $SecurePassword
}
$Credentials = New-Object System.Management.Automation.PSCredential($From,$Passwd)
$SMTPServer = 'smtp.gmail.com'
$SMTPPort = '587'
if (!$Attachment) {
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Credentials
} else {
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Credentials -Attachments $Attachment
}
}
}