我如何从SQL发送电子邮件 [英] How do I sent email from SQL

查看:98
本文介绍了我如何从SQL发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从sql发送邮件。我创建个人资料但邮件没有发送。

邮件状态在sysmail_allitems表中失败



我尝试过:



  GO  
sp_CONFIGURE ' Database Mail XPs' 1
GO
RECONFIGURE
GO

USE MSDB
GO

使用 msdb
go
DECLARE @ SUB VARCHAR 100
SET @ SUB =( SELECT ' 员工报告' + replace( convert NVARCHAR ,getdate(), 106 ),' < span class =code-string>',' /'))
EXEC sp_send_dbmail @ profile_name = ' test Profile'
@ recipients = ' pandikkl01@gmail.com',@ subject = @SUB,
@ body = ' 附件文件已发送'
@query = ' SELECT * EMPLOYEEMAS; ,
@query_attachment_filename ='
test.csv '
@ attach_query_result_as_file = 1 ,
@ exclude_query_output = 1,
@query_result_separator ='
' ,@ query_result_width = 32767,
@ query_result_no_padding = 1,
@query_result_header = 1
go

解决方案

阅读文档: sp_send_dbmail(Transact-SQL) [ ^ ]


你可以也可以借助以下链接:如何使用SQL发送邮件服务器:第1部分 [ ^ ]

I tried to send mail from sql. i create profile but mail not send.
mail status is failed in sysmail_allitems table

What I have tried:

GO
sp_CONFIGURE 	'Database Mail XPs', 1 
GO
RECONFIGURE
GO 

USE MSDB
GO

use msdb
go
DECLARE @SUB VARCHAR(100)
SET @SUB = (SELECT 'Employee Report on '+ replace(convert(NVARCHAR, getdate(), 106), ' ', '/')) 
 EXEC sp_send_dbmail @profile_name='test Profile',
@recipients='pandikkl01@gmail.com', @subject=@SUB, 
@body='Attachment File Sent', 
@query= ' SELECT * EMPLOYEEMAS; ,
@query_attachment_filename='test.csv',
@attach_query_result_as_file=1,
@exclude_query_output=1,
@query_result_separator='	',@query_result_width =32767,
@query_result_no_padding=1,
@query_result_header =1
go

解决方案

Read the documentation : sp_send_dbmail (Transact-SQL)[^]


you can also take the help of this link: How To Send Mail Using SQL Server: Part 1[^]


这篇关于我如何从SQL发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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