在.net中,大家知道,可以使用system.web.mail來發送郵件。在framework 1.1下支持驗證。
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 );
}
以前我曾寫過在.net下發送郵件的方法,詳見:
http://dev.csdn.net/develop/article/17/17189.shtm
 
sql server中,我們一般使用sql本身的郵件發送方式,但需要配置exchage server、outlook等,也是一個比較繁瑣的事情。很多人抱怨說配置不成功。
其實,我們可以在 sql server中創建 ole 對象實例,調用iis smtp自帶的發送組件來實現郵件發送。
我們建立這個存儲過程,你需要修改的地方是,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' 
--下面三條語句是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','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
--判斷出錯
if @hr <> 0
begin
   exec sp_oageterrorinfo @object   
   return @object
end
print 'success'
exec @hr = sp_oadestroy @object
go 
注意:必須確保安裝smtp,可以訪問cdo對象。
(摘自李洪根)