Reputation: 169
I have looked all over the web and cannot find exactly what I am looking for. I am trying to write a Powershell (V2) script that emails a file using our internal Exchange server, but doesn't require Outlook. I have a user account to use for this, but I don't have Outlook available for the server it runs on. Can someone either provide a script (Or even a method) that allows me to send an email with a specified attachment, using an Exchange mailbox?
Thanks!
Upvotes: 1
Views: 14905
Reputation: 126902
You can use the Send-MailMessage cmdlet. Type this at your console for more help:
Get-Help Send-MailMessage -Full
Check the second code example at the examples section:
Get-Help Send-MailMessage -Examples
Upvotes: 6
Reputation: 744
This should do the trick but is missing the attachment. That shouldn't be hard to add.
function submit_report_smtp{
param($report)
trap{return 1}
$smtp_client = New-Object system.Net.Mail.SmtpClient
$smtp_client.Host = $smtp_host
$credentials = New-Object system.Net.NetworkCredential
$credentials.UserName = $smtp_user
$credentials.Password = $smtp_pass
$smtp_client.Credentials = $credentials
$smtp_client.send($smtp_from, $smtp_to, $title,$report)
return 0
}
Upvotes: 0