Powershell Function to send email

Function Send-Email{ param( [parameter(Mandatory)] [string]$mailFrom , [parameter(Mandatory)] [string[]]$mailTo , [parameter(Mandatory)] [string]$mailSubject , [string]$mailBody , [string]$mailAttachment ) $smtpServer="email.mysmtpserver.com" $msg = new-object Net.Mail.MailMessage $smtp = new-object Net.Mail.SmtpClient($smtpServer) $att =new-object Net.Mail.Attachment($mailAttachment) $msg.From = $mailFrom $msg.To.Add($mailTo) $msg.Subject = $mailSubject $msg.Body = $mailBody $msg.Attachments.Add($att) $smtp.Send($msg) $att.Dispose() }

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sanchit Wadhwa

Sanchit Wadhwa

I help solve data problems |Need help ? email me > imsunchip@gmail.com | website > sanchitwadhwa.com | ❤ Books, music, dance, food, podcasts, soccer, writing