In a lot of data analysis and integration scenarios, we need to understand the database of key scripts or job execution. This time email alert is a good way to notice. This article starts with a zero, step-by-step description of how to use SQL Server to send messages.
Environment: 126 mailbox. SQL Server 2012. 1. Configure SMTP permissions for a mailbox (most mailboxes are turned off by default, so manual authentication is required) Login 126 Email---"Set---" Pop3/smtp/imap
2 tick POP3/SMTP service, IMAP/SMTP service, this time will prompt "Please set the authorization code is turned on the service", click OK.
3 on the Authorization code page, click "Open", after the phone verification, set the authorization code. Please note: The authorization code here is the login password used by the client in the future! the following settings are followed:
4 Log on to SQL Server, manage---Database Mail---Right-click, configure Database Mail
5 Select the first item: Install Database Mail by performing the following tasks.
6. Set the profile name. (This configuration will be used later to send mail) Click "Add" to go to the detailed configuration page.
7. Configure as shown. There are two points to note:1. Use a different mailbox with a different port number. 126 The port number of the mailbox is 25, if you use another mailbox, you can go onlinecheck out how many SMTP port numbers they use by default. 2. The following identity authentication password must be the previously mentioned authorization code! Not the login password of the mailbox. (the concept of authorization code is also to ensure that the mailbox password is not compromised, you can open SMTP permissions to the appropriate client.) )
8. Click OK and next to complete the configuration of the mailbox configuration file.
9. Send a test message. Right-click Database Mail---Send Test e-mail. Enter the appropriate recipients (multiple people are separated by semicolons)
10. E-Mail received as follows:
11. Finally, add how to send mail via SQL script. (The previous configuration is required) EXEC Msdb.dbo.sp_send_dbmail@profile_name = ' Testdbemail ',@recipients = ' [email protected]; [Email protected] ',@subject = ' Test ',@body = ' Test sql Server sent email. '
Send mail using SQL Server