-
Notifications
You must be signed in to change notification settings - Fork 0
/
Email.ps1
43 lines (34 loc) · 1.31 KB
/
Email.ps1
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
$name="Bryan A"
$Email = "user@gmail.com";
$Password= "password";
Function MAIL{
Param (
[Parameter(Mandatory=$true)] [String]$s,
[Parameter(Mandatory=$true)] [String]$c,
[Parameter(mandatory=$false)] [String]$a="none",
[Parameter(Mandatory=$true)] [String]$to
)
$message = new-object Net.Mail.MailMessage;
$message.From = "$name <$Email>";
$message.IsBodyHTML=$true
$message.To.Add($to);
$message.Subject = $s;
$message.Body = $c;
if(($PSBoundParameters.ContainsKey('a')) -and $a){
$attachment = New-Object Net.Mail.Attachment($a);
$message.Attachments.Add($attachment);
}
$smtp = new-object Net.Mail.SmtpClient("smtp.gmail.com", "587");
$smtp.EnableSSL = $true;
$smtp.Credentials = New-Object System.Net.NetworkCredential($Email, $Password);
$smtp.send($message);
write-host "Mail Sent" ;
if(($PSBoundParameters.ContainsKey('a')) -and $a){
$attachment.Dispose();
}
}
$BM ="lo que sea awe"
#atachment
#MAIL -s "subject hello" -c "body text" -a 'C:\backup\file.txt' "user@gmail.com";
#simple
#MAIL -s "subject hello" -c "body text" -to "user@gmail.com";