SQL Server Express is a very common version of SQL Server used when creating a website. In this article we will have a look at how you can configure DBMail in your SQL Server Express instance on a Windows Azure virtual machine. The majority of steps have not changed since SQL Server 2005 was first released.
Configure SMTP Service
For SQL Server DBMail to work on your Azure Virtual Server we need to have access to SMTP service to be able to send emails. To configure the SMTP service we have to add the SMTP server feature.
-
Start Server Manager | Add Roles and Features
-
Click Next until you are on the Select Features Page
-
Scroll down until you find SMTP Server | Ensure you check this option
-
Click Next through to the end and then install the feature.
Now that we have the SMTP Server feature installed we need to configure our environment in preparation for use with our instance of SQL Server SQL Express. Start IIS 6.0 Manager from the installed programs and expand the local computer object until you can see SMTP Virtual Server.
-
Right Click on the SMTP Virtual Server | Properties.
-
On the Access Tab | Select Authentication and ensure “Anonymous Access” is selected
-
On the Access Tab | Select Relay and ensure “All except the list below” is selected
-
On the Delivery Tab | Select Outbound Security
-
Enter your SMTP provider details in Smart Host
-
Eg – smtp.gmail.com
-
-
On the Delivery Tab | Select Outbound Connections
-
Enter the associated Port for you your SMTP provider
-
Eg – 587
-
-
On the Delivery Tab | Select Advanced
-
Select Basic Authentication
-
Enter your email account and password associated with your SMTP provider above
-
Eg – [email protected]
-
Ensure TLS Encryption is selected
-
Congratulations we have just configure our SMTP server that we are going to use with our SQL Server Express Instance.
Configure DBMail in SQL Express
To complete our setup to be able to send emails from within our Instance of SQL Server Express we need to configure DBMail. This configuration is normally pretty simple and is able to be completed from within SQL Server Management Studio (SSMS) however as SQL Express is a cut down version we do not have the ability to do this all via the GUI wizard.
The steps to take are listed below and should be run in SSMS on your SQL Server Express Instance.
Enable DBMail
-- Enable Advanced options to confirm DBMail is not already enabled sp_configure 'Show Advanced Options',1 GO RECONFIGURE GO -- Enable DBMail configuration option sp_configure 'Database Mail XPs',1; GO RECONFIGURE GO -- Turn off Advanced Options sp_configure 'Show Advanced Options',0 GO RECONFIGURE GO
Create DBMail Account
-- Create DBMail Account EXECUTE msdb.dbo.sysmail_add_account_sp @account_name = 'MailNotification', @description = 'Mail Account for Email Notifications', @email_address = '[email protected]', @display_name = 'My Account', @mailserver_name = 'localhost';
Create DBMail Profile
-- Create DBMail Profile EXECUTE msdb.dbo.sysmail_add_profile_sp @profile_name = 'MailProfile', @description = 'Mail Profile';
Add DBMail Account to DBMail Profile
-- Add DBMail Profile Account EXECUTE msdb.dbo.sysmail_add_profileaccount_sp @profile_name = 'MailProfile', @account_name = 'MailNotification', @sequence_number = 1;
Set DBMail Principal Profile
-- Add DBMail Principal Profile EXECUTE msdb.dbo.sysmail_add_principalprofile_sp @profile_name = 'MailProfile', @principal_name = 'Public', @is_default = 1;
Send a Test Email
DECLARE @EmailBody NVARCHAR(255); SET @EmailBody = 'Test Email Notification setup'; EXEC msdb.dbo.sp_send_dbmail @recipients='[email protected]', @subject = 'Blog Post Comment Notification', @body = @EmailBody, @body_format = 'HTML';
Enjoy the use of your DBMail setup.
Leave a Reply