当前位置: 代码迷 >> Sql Server >> sql email发送邮件,发送邮件的信箱里给出提示:Reason: Requested action not taken: no smtp MX only
  详细解决方案

sql email发送邮件,发送邮件的信箱里给出提示:Reason: Requested action not taken: no smtp MX only

热度:481   发布时间:2016-04-27 11:37:36.0
sql email发送邮件,发送邮件的邮箱里给出提示:Reason: Requested action not taken: no smtp MX only
写了个发送邮件的procedure,SMTP的服务器是网上下的:SMTP Server Pro。
OLE属性设置如下
 EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'

  EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', '127.0.0.1' 
最后有条打印语句:Mail Sent!

然后执行该procedure,[email protected],[email protected],打印语句也看到了
但是在发送邮箱里收到一封邮件,内容是:
The message was undeliverable due to an error in receiving system. 
Listed are all the recepients with appropriate explanation from remote system
on the reasons, why the message could not be delivered:

Email:[email protected]
Reason: Requested action not taken: no smtp MX only,mx12,wMmowJDr_+8hKgNNFVqiAA--.132S3 1292053026

看了下端口25打开的。请问这是怎么回事???

------解决方案--------------------
没做过,给篇文章,自己参考:
SQL Server怎样配置发送电子邮件
ZDNet 软件频道 更新时间:2007-11-26 作者:21tx 来源:21tx
本文关键词:电子邮件 配置 数据库 SQL Server 
通常大家都知道:SQL Server与Microsoft Exchange Server集成性很好,关于这方面的配置,在SQL Server的联机帮助里有详细的说明,在此不再赘述。然而我们更关心的问题是:在没有Exchange Server的情况下,如何配置SQL Server利用Internet 邮件服务器发送邮件? 


笔者曾为这问题伤透了脑筋,搜遍了互联网上的相关资料,发现仅有的几篇资料中有的是一笔带过,有的虽然介绍了操作步骤,可按照步骤一步一步操作下来,结果总是失败。为此笔者反复实验,终于找到一种简单有效的方法,不敢独自享受,下面是详细的配置步骤,如果您在操作的过程中碰到什么问题,请留言。 


测试环境:


1 Windows 2000 Server
2 SQL Server 2000+SP3
3 Microsoft OutLook (Office 2000)


准备一个Internet邮件帐户:


测试电子邮件帐户:[email protected]
Smtp服务器 smtp.163.com
pop3服务器 pop.163.com


步骤一: 更改电子邮件配置


1 打开Microsoft OutLook 单击“工具”菜单中的“选项”,然后单击“邮件服务”选项卡。
2 单击“重新配置邮件支持”。
3 选择“用于企业或工作组”选项
4 重新启动Microsoft OutLook


步骤二: 添加配置文件


1 单击“工具”菜单中的“服务”,然后单击“添加”按钮。
2 选择"Internet 电子邮件",单击“确定”。
3 下面的步骤是设置电子邮件帐号,请参考Microsoft Outlook帮助文件,这里不再赘述。
4 利用配置好的电子邮件帐号收发邮件,确认配置成功。


步骤三: 配置MSSQLSERVER服务采用邮件配置文件


1 重新启动MSSQLSERVER服务(必须的,否则MSSQLSERVER服务检测不到上一步骤添加的配置文件)
2 打开企业管理器->展开服务器->支持服务->右击"邮件"->点击下拉框,你会发现
"Microsoft Outlook Internet Settings"选项,点击"测试"。如果弹出表示成功的对话框,那恭喜你,已经 大功告成了。


步骤四:享受你的劳动成果


1 打开SQL Server的查询分析器


2 输入下列SQL语句,执行
exec master..xp_sendmail [email protected]','Hello,World!'


3 好了,去你的邮箱收邮件去吧! 


注意事项:以上的配置过程要求以MSSQLSERVER服务采用的Windows帐号登录Windows 2000 Server,即你登录计算机所采用的帐号要和MSSQLSERVER服务采用的Windows帐号相同。

------解决方案--------------------
SQL code
CREATE PROCEDURE [dbo].[send_mail2]   @From varchar(1000) ,  --发件人   @To varchar(1000) ,   --收件人   @Subject nvarchar(128)='', --标题   @Body nvarchar(4000) ='' --正文--with encryption/*********************************************************************This stored procedure takes the parameters and sends an e-mail.All the mail configurations are hard-coded in the stored procedure.Comments are added to the stored procedure where necessary.References to the CDOSYS objects are at the following MSDN Web site:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_messaging.asp***********************************************************************/ASDeclare @iMsg intDeclare @hr intDeclare @source varchar(255)Declare @description varchar(500)Declare @output varchar(1000)Declare @smtpserver varchar(200)Declare @sendusername varchar(200)Declare @sendpassword varchar(200)      --please set the values before excute the stored procedureset @smtpserver  = 'smtp.163.com'  --smtp服务器set @sendusername = ''--发送认证:用户名set @sendpassword = ''--发送认证:密码if @sendusername='' or  @sendpassword=''begin raiserror 50000 'please set the @sendusername and  @sendpassword values before excute the stored procedure' return -1end--replace the quotation marksset @Subject=replace(@Subject,'''','''''')set @Body=replace(@Body,'''','''''')--************* Create the CDO.Message Object ************************EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT--***************Configuring the Message Object ******************-- This is to configure a remote SMTP server.-- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_schema_configuration_sendusing.aspEXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'-- This is to configure the Server Name or IP address.-- Replace MailServerName by the name or IP of your SMTP Server.EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', @smtpserver--EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value','1' EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value', @sendusernameEXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value', @sendpassword -- Save the configurations to the message object.EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null-- Set the e-mail parameters.EXEC @hr = sp_OASetProperty @iMsg, 'To', @ToEXEC @hr = sp_OASetProperty @iMsg, 'From', @FromEXEC @hr = sp_OASetProperty @iMsg, 'Subject', @Subject-- If you are using HTML e-mail, use 'HTMLBody' instead of 'TextBody'.EXEC @hr = sp_OASetProperty @iMsg, 'TextBody', @BodyEXEC @hr = sp_OAMethod @iMsg, 'Send', NULLif @@error<>0 or @hr<>0begin raiserror 55000 '<send_mail> Error: send mail failed.'endelse begin print 'Success: send mail ok.'endEXEC @hr = sp_OAGetErrorInfo NULL, @source OUT, @description OUTIF @hr = 0BEGIN SELECT @output = '<send_mail> Error Source: ' + @source PRINT  @output SELECT @output = '<send_mail> Error Description: ' + @description PRINT  @outputENDELSEBEGIN PRINT '  sp_OAGetErrorInfo failed.' RETURNEND-- Do some error handling after each step if you have to.-- Clean up the objects created.EXEC @hr = sp_OADestroy @iMsgGO
  相关解决方案