Tuesday, 14 August 2012

Sending email through Amazon SES with PowerShell

Amazon Simple Email Service (Amazon SES) is a highly scalable and cost-effective bulk and transactional email-sending service for businesses and developers. 

Here is a pretty basic PowerShell script that will send email through Amazon SES SMTP interface. This assumes you already have SES enabled, and you at least have access to send email from the SES sandbox – an environment specifically designed for developers to test and evaluate the service.


$smtpServer = "email-smtp.us-east-1.amazonaws.com" 
$smtpPort = 587  
$username = "your username"
$password = "your password"  
$from = "[email protected]"
$to = "[email protected]"
$subject = "Test e-mail with PowerShell"
$body = "This is a test e-mail sending with using PowerShell"

$smtp = new-object Net.Mail.SmtpClient($smtpServer, $smtpPort)
$smtp.EnableSsl = $true 

$smtp.Credentials = new-object Net.NetworkCredential($username, $password)
$msg = new-object Net.Mail.MailMessage
$msg.From = $from
$msg.To.Add($to)
$msg.Subject = $subject
$msg.Body = $body
$smtp.Send($msg)

No comments:

Post a Comment