PowerShellでメールを送信するサンプルコードを以下に記します。
単純なメール送信サンプルコードになります。
$smtp = "smtp" # SMTPサーバ $port = 25 # SMTPポート $from = "from@domain" $to = "to@domain" $body = "メール本文" $SmtpClient = New-Object Net.Mail.SmtpClient($smtp,$port) $Message = New-Object Net.Mail.MailMessage($from, $to, $subject, $body) $SmtpClient.Send($Message)
単純なHTMLメール送信サンプルコードになります。
$smtp = "smtp" # SMTPサーバ $port = 25 # SMTPポート $from = "from@domain" $to = "to@domain" $body = "<b>メール本文</b>" $SmtpClient = New-Object Net.Mail.SmtpClient($smtp,$port) $Message = New-Object Net.Mail.MailMessage($from, $to, $subject, $body) $Message.IsBodyHtml = $True $SmtpClient.Send($Message)
以上、PowerShellでメールを送信するサンプルコードでした。