Microsoft SQL Server on Windows Azure Virtual Machines

The writers of this blog are a part of the Microsoft SQL Server team. We will be blogging about our tools, scripts, webcasts, and miscellaneous tips that will help you get the most out of SQL Server components on Windows Azure Virtual machines

Database Mail – Validating your SMTP mail server configuration using powershell

Database Mail – Validating your SMTP mail server configuration using powershell

  • Comments 2

 

Database mail relies on .NET framework's SMTP client API to send emails. You could write a simple power shell script like this to test out if you are able to send mails using your smtp server

Sample Powershell Code to send email:

 1: $smtpServer = "emailserver"
 2: $smtpPort = 25
 3: $emailFrom = "from@domain.com"
 4: $emailTo = "to@domain.com"
 5: $smtp = new-object Net.Mail.SmtpClient($smtpServer)
 6: $smtp.Port = $smtpPort
 7: $subject = "subject" 
 8: $body = "body " 
 9: $smtp.Send($emailFrom, $emailTo, $subject, $body)

This posting is provided "AS IS" with no warranties, and confers no rights. 
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Leave a Comment
  • Please add 3 and 6 and type the answer here:
  • Post
  • What about if the server requires authentication (like BPOS)? Thanks!

  • When you configure Database Mail, you will need to provide the credential as the required authentication.  In this Powershell example, it means to set $smtp.Credentials to the authenticated account.

Page 1 of 1 (2 items)