在sql server 2005中发送邮件 [英] sending mail in sql server 2005

查看:84
本文介绍了在sql server 2005中发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个表,其中包含25条员工记录.不,我希望每个星期一都要通过sql server通过存储过程或其他方式将邮件发送给所有员工.

请帮帮我.

谢谢
Mohd wasif

Hi All,

I have a table that has 25 records of employees.No I want that each monday a mail is to to be send to all employees through sql server by stored procedure or something else.

Please help me.

Thanks
Mohd wasif

推荐答案

SQL Server 2005数据库邮件提供了一些用于发送电子邮件的选项.这些选项包括发送附件,设置敏感性和重要性(包括查询结果)以及将电子邮件格式设置为HTML格式.您可以使用链接 http://www.techrepublic进行设置.com/article/setting-up-database-mail-in-sql-server-2005/6161839 [
SQL Server 2005 Database Mail provides several options for sending e-mail messages. These options include sending attachments, setting sensitivity and importance, including query results, and formatting the e-mail message in an HTML format. You can set up using the link http://www.techrepublic.com/article/setting-up-database-mail-in-sql-server-2005/6161839[^]

Here is the sample SQL code to send mail:

EXEC msdb.dbo.sp_send_dbmail
 @recipients=N'chapman.tim@gmail.com',
@body='Message Body', 
 @subject ='Message Subject',
@profile_name ='Database-mailProfile',
@file_attachments ='C:\FileAttachment.txt';


CREATE PROCEDURE [dbo].[sp_send_mail] 
@From varchar(100),
@To varchar(100),
@Subject varchar(100),
@Body varchar(4000),
@CC varchar(100) = null,
@BCC varchar(100) = null
AS
Declare @MailID int
Declare @hr int
EXEC @hr = sp_OACreate 'CDONTS.NewMail', @MailID OUT
EXEC @hr = sp_OASetProperty @MailID, 'From',@From
EXEC @hr = sp_OASetProperty @MailID, 'Body', @Body
EXEC @hr = sp_OASetProperty @MailID, 'BCC',@BCC
EXEC @hr = sp_OASetProperty @MailID, 'CC', @CC
EXEC @hr = sp_OASetProperty @MailID, 'Subject', @Subject
EXEC @hr = sp_OASetProperty @MailID, 'To', @To
EXEC @hr = sp_OAMethod @MailID, 'Send', NULL
EXEC @hr = sp_OADestroy @MailID




在cp上获得一个很好的示例:
SQL SERVER-2008-配置数据库邮件-从SQL数据库发送电子邮件 [




Get a good example on cp: SQL SERVER - 2008 - Configure Database Mail - Send Email From SQL Database[^]


这些将为您提供帮助.

http://blog .sqlauthority.com/2008/08/23/sql-server-2008-configure-database-mail-send-email-from-sql-database/ [ http://classicasp.aspfaq.com/email/how-do-i-send-e-mail-from-sql-server.html [
These will help you.

http://blog.sqlauthority.com/2008/08/23/sql-server-2008-configure-database-mail-send-email-from-sql-database/[^]

http://classicasp.aspfaq.com/email/how-do-i-send-e-mail-from-sql-server.html[^]


这篇关于在sql server 2005中发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆