首页 > 数据库 > mysql教程 > How to send email using sqlserver

How to send email using sqlserver

WBOY
发布: 2016-06-07 15:33:58
原创
1158 人浏览过

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 d

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.

How to send email using sqlserver

Step 3

The following window appears:

How to send email using sqlserver

Click Next.

Step 4

Select the Set up Database Mail by performing the following tasks: radio button.

How to send email using sqlserver

Step 5

Click Next, then a confirmation box appears; click OK on that.

How to send email using sqlserver

Step 6

When you click OK, then write the profile name description and click on Add.

How to send email using sqlserver

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.

How to send email using sqlserver

Step 8

Then in the new window, it will show your profile, check that and click Next.

How to send email using sqlserver

Step 9

Then in the new window, the Configure System Parameters description is shown.

How to send email using sqlserver

Step 10

Click Next. It will show a confirmation about your profile; click Finish.

How to send email using sqlserver

Step 11

Now the email service has been configured, click Close.

How to send email using sqlserver

Step 12

Send a test email by right-clicking on database mail and click Send Test E-Mail.

How to send email using sqlserver

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!!

How to send email using sqlserver

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 the sp_configure Stored Procedure, as shown here:

How to send email using sqlserver Collapse | Copy Code

    sp_CONFIGURE <span>'</span><span>show advanced'</span>, <span>1</span>  
    <span>GO</span>  
    <span>RECONFIGURE</span>  
    <span>GO</span>  
    sp_CONFIGURE <span>'</span><span>Database Mail XPs'</span>, <span>1</span>  
    <span>GO</span>  
    <span>RECONFIGURE</span>  
    <span>GO</span>  
登录后复制

Output Message

The Configuration option "show advanced options" changed from 0 to 1. Run the RECONFIGURE statement to install.

The configuration option "Database Mail XPs" changed from 1 to 1. Run the RECONFIGURE statement 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.

How to send email using sqlserver Collapse | Copy Code

    <span>GO</span>  
    <span>EXEC</span> sp_send_dbmail @profile_name=<span>'</span><span>MyTestMail'</span>,  
    @recipients=<span>'</span><span>manishki@live.com'</span>,  
    @subject=<span>'</span><span>My Test Mail Service.'</span>,  
    @body=<span>'</span><span>Database Mail Received Successfully.'</span>   
登录后复制

This is the body of this message.

Note

If you are using a database other than msdb, then use a stored procedure like msdb.dbo.sp_send_dbmail. The log can be checked in sysmail_log table as shown below:

How to send email using sqlserver Collapse | Copy Code

    <span>SELECT</span> * <span>FROM</span> sysmail_mailitems  
    <span>GO</span>  
    <span>SELECT</span> * <span>FROM</span> sysmail_log  
    <span>GO</span>  
    <span>select</span> * <span>from</span> sysmail_log  
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板