Powershell- Scripting an email from Exchange

14,756

Solution 1

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
}

Solution 2

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
Share:
14,756
user1467163
Author by

user1467163

Updated on June 04, 2022

Comments

  • user1467163
    user1467163 about 2 years

    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!

  • Shay Levy
    Shay Levy about 12 years
    Thanks @Christian, I'm not what I was thinking about when writing this, updating my answer.