zoukankan      html  css  js  c++  java
  • 在SQL Server中,不使用“SQL 邮件”的情况下发送邮件

    SET QUOTED_IDENTIFIER ON 
    GO
    SET ANSI_NULLS ON 
    GO

    ALTER  PROCEDURE usp_SendMail @To varchar(100) ,@Subject varchar(400)=' '@Body varchar(8000=' ' 

    AS 

    Declare @object int 
    Declare @hr int 

    EXEC @hr = sp_OACreate 'CDO.Message'@object OUT 

    EXEC @hr = sp_OASetProperty @object'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2' 
    EXEC @hr = sp_OASetProperty @object'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value''SMTP'  --SMTP地址

    --下面三条语句是smtp验证,如果服务器需要验证,则必须要这三句,你需要修改用户名和密码
    EXEC @hr = sp_OASetProperty @object'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value','1' 
    EXEC @hr = sp_OASetProperty @object'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value','your email address'  --你的邮件地址
    EXEC @hr = sp_OASetProperty @object'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value','yourpassword'  --邮箱密码

    EXEC @hr = sp_OAMethod @object'Configuration.Fields.Update'null
    EXEC @hr = sp_OASetProperty @object'To'@To
    EXEC @hr = sp_OASetProperty @object'Bcc''goodspeedwang@yahoo.com.cn'
    EXEC @hr = sp_OASetProperty @object'From''Goodspeed <goodspeed@idg-rbi.com.cn>' 
    EXEC @hr = sp_OASetProperty @object'Subject'@Subject
    EXEC @hr = sp_OASetProperty @object'BodyFormat''MailFormat.Text'

    EXEC @hr = sp_OASetProperty @object'TextBody'@Body -- Text格式

    SET @Body = REPLACE(@Body,CHAR(13),'<br />')
    EXEC @hr = sp_OASetProperty @object'HtmlBody',@Body --HTML格式的邮件
    EXEC @hr = sp_OAMethod @object'Send'NULL

    --判断出错
    IF @hr <> 0
    BEGIN
       
    EXEC sp_OAGetErrorInfo @object   
       
    RETURN @object
    END
    PRINT 'success'
    EXEC @hr = sp_OADestroy @object


    GO
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO

    更多cdo的信息就访问
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/exchanchor/htms/msexchsvr_cdo_top.asp
  • 相关阅读:
    skynet debug console 使用
    在linux上定时修改root密码,以邮件形式发送给使用者
    在linux nginx服务器上,给内网ip配置https
    在linux apache服务器上,给内网ip配置https
    redis集群配置
    记一次删除k8s namespace无法删除的问题
    向docker镜像中传递变量的两种方式
    用kubeadm简单部署k8s
    第十六天python3 文件IO(二)
    第十五天python3 文件IO(一)
  • 原文地址:https://www.cnblogs.com/goodspeed/p/145723.html
Copyright © 2011-2022 走看看