Send email with attachment in powershell
$file = “C:\somename.html”
$EmailFrom = “FromMail@Domain.com”
$EmailTo = “ToMail@Domain.com”
$SMTPServer = “Your Smtp Server Name”
$EmailSubject = “Enter Your Subject”
$att = new-object Net.Mail.Attachment($file)
#Send mail with attachment
$mailmessage = New-Object system.net.mail.mailmessage
$mailmessage.from = ($EmailFrom)
$mailmessage.To.add($EmailTo)
$mailmessage.Subject = $EmailSubject
$mailmessage.Body = $Body
$mailmessage.IsBodyHTML = $true
$mailmessage.Attachments.Add($att)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer)
$SMTPClient.Send($mailmessage)
$att.Dispose()
$file = “C:\somename.html”
$EmailFrom = “FromMail@Domain.com”
$EmailTo = “ToMail@Domain.com”
$SMTPServer = “Your Smtp Server Name”
$EmailSubject = “Enter Your Subject”
$att = new-object Net.Mail.Attachment($file)
#Send mail with attachment
$mailmessage = New-Object system.net.mail.mailmessage
$mailmessage.from = ($EmailFrom)
$mailmessage.To.add($EmailTo)
$mailmessage.Subject = $EmailSubject
$mailmessage.Body = $Body
$mailmessage.IsBodyHTML = $true
$mailmessage.Attachments.Add($att)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer)
$SMTPClient.Send($mailmessage)
$att.Dispose()