Collaboration-2-Go


Lösungen und Software-Entwicklung im Collaboration Umfeld, insbesondere Microsoft SharePoint, Microsoft Exchange und Microsoft Office.

Support


Mobil: +49 (152) 53 97 78 79
Mail: service@collaboration-2-go.de
Weitere Kontaktmöglichkeiten: Kontaktseite
Dekoration: Köln



Send Mail
Created: 04.10.2017
Categories: PowerShell

      If you want to send a mail with an attachment using PowerShell you can you this code:

      
function SendSmtpMail($server, $sender, $recipients, $subject, $body, $file)
{
    $msg = new-object Net.Mail.MailMessage
    $smtpServer = new-object Net.Mail.SmtpClient($server)
    $msg.From = $sender
    $msg.Subject = $subject
    $msg.Body = $body

    foreach ($recipient in $recipients)
    {
        $msg.To.Add($recipient)
    }

    if ($file -ne "")
    {
        $att = new-object Net.Mail.Attachment($file)
        $msg.Attachments.Add($att)
    }

    $smtpServer.Send($msg)

    if ($file -ne "")
    {
      $att.Dispose()
    }
}

$smtpServer = "my smtp server"
$file = "path to file"
$recipients = @( "user1@test.de", "user2@test.de" )
$sender = "sender@mydomain.com"
$subject = "My Subject"
$body = "My Mail Text"

SendSmtpMail $smtpServer $sender $recipients $subject $body $file

    

Send us a Comment!