视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
Howtosendemailusingsqlserver
2020-11-09 15:36:28 责编:小采
文档


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.

    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 the sp_configure Stored 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 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.

    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 like msdb.dbo.sp_send_dbmail. The log can be checked in sysmail_log table as shown below:

    Collapse | Copy Code

     SELECT * FROM sysmail_mailitems 
     GO 
     SELECT * FROM sysmail_log 
     GO 
     select * from sysmail_log 
    

    下载本文
    显示全文
    专题