How to send email using sqlserver
2014-11-28 03:25
591 查看
This is from CodeProject:http://www.codeproject.com/Articles/846204/How-To-Send-Mail-Using-SQL-Server-Part
Introduction
There are three parts for this tutorial:Configure email profile and send test email using SQL Server
Select and send data in mail
Schedule daily mail from SQL Server
Step 1
Log in to SQL Server 2008 with a correct user name and password.Step 2
Expand the Management tab, then select SQL Server Logs, then right-click on Database Mail, then select Configure Database Mail.Step 3
The following window appears:Click Next.
Step 4
Select the Set up Database Mail by performing the following tasks: radio button.Step 5
Click Next, then a confirmation box appears; click OK on that.Step 6
When you click OK, then write the profile name description and click on Add.Step 7
Then, a new window appears where you provide your profile name and configure Outgoing Mail Server(SMTP) then click Basic authentication and provide your email id and password then click OK.Step 8
Then in the new window, it will show your profile, check that and click Next.Step 9
Then in the new window, the Configure System Parameters description is shown.Step 10
Click Next. It will show a confirmation about your profile; click Finish.Step 11
Now the email service has been configured, click Close.Step 12
Send a test email by right-clicking on database mail and click Send Test E-Mail.Step 13
Provide the Test Email Id and click On Send Test E-Mail. Then check your mail to see if you got the mail. Enjoy!!Note
After the Account and the Profile are created successfully, we need to configure the Database Mail. To configure it, we need to enable the Database Mail XPs parameter using thesp_configureStored Procedure, as shown here:
Collapse |
Copy Code
sp_CONFIGURE 'show advanced', 1 GO RECONFIGURE GO sp_CONFIGURE 'Database Mail XPs', 1 GO RECONFIGURE GO
Output Message
The Configuration option "show advanced options" changed from 0 to 1. Run theRECONFIGUREstatement to install.
The configuration option "Database Mail XPs" changed from 1 to 1. Run the
RECONFIGUREstatement to install.
Use the following query to send mail using query:
Send Mail Query
USE msdb;--Must Use msdb database, otherwise you will get error.
Collapse |
Copy Code
GO EXEC sp_send_dbmail @profile_name='MyTestMail', @recipients='manishki@live.com', @subject='My Test Mail Service.', @body='Database Mail Received Successfully.'
This is the body of this message.
Note
If you are using a database other than msdb, then use a stored procedure likemsdb.dbo.sp_send_dbmail. The log can be checked in
sysmail_logtable as shown below:
Collapse |
Copy Code
SELECT * FROM sysmail_mailitems GO SELECT * FROM sysmail_log GO select * from sysmail_log
相关文章推荐
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server. (文档 ID 885522.1)
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- How to delete all email in the mail server using telnet & WCScript - 如何用 Telnet 删除邮件服务器上的所有邮件
- How to automatic process SSAS cube using SQL Server agent job
- How to test if the server is configured well to send email to external accoun
- How to send an email from oracle workflow process using an AdHocRole?
- prjSendMailInUniversity - How to send email using VB & Winsock - 邮件发送接收程序 - VB6 + Winsock
- How to send Email using C#
- [转]create a basic sql server 2005 trigger to send email alerts
- Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email
- How to read and save Images in a Sql Server Database using ADO.NET and C#
- [转]How to find who is using / eating up the Virtual Address Space on your SQL Server
- Using exchange server to send email in Powershell
- How to send Email through external SMTP server on Ubuntu 14.04
- How to check the MS SQL Server job run status by using Script
- How to make NAnt send an email using a real account
- How to send email via vbs using cdo