Sat. Dec 14th, 2019

Samir Daoudi's Technical Blog

SharePoint, Office 365, C#, .Net, SQL Server News, Tips, Ebooks, Events, Webinars ….etc

Send email with attachment in powershell

$Body = "get the information here to show the data with attachement"  | Set-Content C:\somename.html $att = new-object Net ail #Send mail with attachment $mailmessage $mailmessage $mailmessage $mailmessage ail $att
$Body = “get the information here to show the data with attachement”  | Set-Content C:\somename.html

$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()

Leave a comment

Copyright © All rights reserved. | Newsphere by AF themes.
Show Buttons
Hide Buttons

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.