国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > SQL Server > 正文

SQL Server中發(fā)送郵件的新方式

2024-08-31 00:48:16
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
  • 本文來(lái)源于網(wǎng)頁(yè)設(shè)計(jì)愛(ài)好者web開(kāi)發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問(wèn)。

  • 說(shuō)是新方式,其實(shí)也是早就用到的技術(shù)了,所以放上來(lái)!

    在.net中,大家知道,可以使用system.web.mail來(lái)發(fā)送郵件。在framework 1.1下支持驗(yàn)證。

    private void page_load(object sender, system.eventargs e)
    {
           mailmessage mail = new mailmessage();
           mail.to = "[email protected]";
           mail.from = "[email protected]";
           mail.subject = "this is a test email.";
           mail.body = "some text goes here";
           mail.fields.add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
           mail.fields.add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
          mail.fields.add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here

        smtpmail.smtpserver = "mail.mycompany.com";  //your real server goes here
        smtpmail.send( mail );
    }

    以前我曾寫(xiě)過(guò)在.net下發(fā)送郵件的方法,詳見(jiàn):

    http://dev.csdn.net/develop/article/17/17189.shtm

     

    sql server中,我們一般使用sql本身的郵件發(fā)送方式,但需要配置exchage server、outlook等,也是一個(gè)比較繁瑣的事情。很多人抱怨說(shuō)配置不成功。

    其實(shí),我們可以在 sql server中創(chuàng)建 ole 對(duì)象實(shí)例,調(diào)用iis smtp自帶的發(fā)送組件來(lái)實(shí)現(xiàn)郵件發(fā)送。

    我們建立這個(gè)存儲(chǔ)過(guò)程,你需要修改的地方是,smtpserver的名字

    create procedure sys_sendmail @from varchar(100) , @to varchar(100) , @bcc varchar(500), @subject varchar(400)=" ", @body ntext =" "

    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.163.com'

    --下面三條語(yǔ)句是smtp驗(yàn)證,如果服務(wù)器需要驗(yàn)證,則必須要這三句,你需要修改用戶名和密碼
    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','lihonggen0'
    exec @hr = sp_oasetproperty @object, 'configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").value','xxx'

    exec @hr = sp_oamethod @object, 'configuration.fields.update', null
    exec @hr = sp_oasetproperty @object, 'to', @to
    exec @hr = sp_oasetproperty @object, 'bcc', @bcc
    exec @hr = sp_oasetproperty @object, 'from', @from
    exec @hr = sp_oasetproperty @object, 'subject', @subject

    exec @hr = sp_oasetproperty @object, 'textbody', @body
    exec @hr = sp_oamethod @object, 'send', null

    --判斷出錯(cuò)
    if @hr <> 0
    begin
       exec sp_oageterrorinfo @object  
       return @object
    end
    print 'success'
    exec @hr = sp_oadestroy @object

    go

    注意:必須確保安裝smtp,可以訪問(wèn)cdo對(duì)象。
    發(fā)表評(píng)論 共有條評(píng)論
    用戶名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 千阳县| 峡江县| 富裕县| 邵武市| 德令哈市| 长岭县| 广德县| 会东县| 建宁县| 六安市| 云浮市| 玛多县| 仲巴县| 通海县| 山丹县| 调兵山市| 高邑县| 安宁市| 临泽县| 祥云县| 桐城市| 海伦市| 东明县| 琼海市| 卢龙县| 巴彦淖尔市| 天镇县| 湘乡市| 娱乐| 泉州市| 赫章县| 怀集县| 秦皇岛市| 玛曲县| 乐山市| 郎溪县| 周至县| 策勒县| 武威市| 宝清县| 临夏市|