Answers for "send email using batch file script"

0

send email using batch file script

$Username      = $args[0]
$EmailPassword = $args[1]

$Username = $Username
$EmailTo = "[email protected]" 
$EmailFrom = "[email protected]"
$Subject = "Email Subject"
$Body = "Email Body"
$SMTPServer = "smtp.gmail.com" 
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom, $EmailTo, $Subject, $Body)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) 
$SMTPClient.EnableSsl = $true 
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $EmailPassword); 
$SMTPClient.Send($SMTPMessage)
Posted by: Guest on November-03-2020
0

batch script send email

Use batch script to call powershell Send-MailMessage

Batch Script:send_email.bat
		C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -command 'E:\path\send_email.ps1

Pwershell Script:send_email.ps1
		Send-MailMessage -From "noreply@$env:computername" -To '<[email protected]>' -Subject 'Blah Blah' -SmtpServer  'smtp.domain.com'  -Attachments 'E:\path\file.log' -BODY "Blah Blah on Host: $env:computername "
Posted by: Guest on September-17-2020

Browse Popular Code Answers by Language