日期:2014-05-18  浏览次数:20638 次

sql2005 如何发mail?
sql2005 如何发mail?

------解决方案--------------------
using System.Web.Mail;
using System.Net;
public string FYJ()
try
{
MailMessage Mail = new MailMessage();
Mail.From = "ceshi@163.com";//发邮件人地址(站长)
Mail.To = "abc@163.com";//目标地址(客户)
Mail.Subject = "测试发送邮件!";//邮件标题
Mail.Body = "哈哈你收到了吗,您的注册用户名是:"+name+" 密码是:"+pwd+" 请保管好你的用户名和密码!谢谢您的加入"; //要发的邮件内容
Mail.BodyFormat = MailFormat.Html;
Mail.Priority = MailPriority.High;
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "你的邮箱帐号");//邮箱的帐户名
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "这里写密你的密码");//邮箱的密码
System.Web.Mail.SmtpMail.SmtpServer = "smtp.163.com";
System.Web.Mail.SmtpMail.Send(Mail);
Response.Write("<script>alert('发送成功!')</script>");
}
catch (Exception exp)
{
Response.Write(exp.Message);
}

}

------解决方案--------------------
使用Database Mail.
------解决方案--------------------
管理--邮件库邮件--配置数据库邮件

EXEC msdb.dbo.sp_send_dbmail
@recipients=N'pdm@163.com',
@body=N'The master database is full.' ; 

------解决方案--------------------
SQL code
SQL Server 并没有内置邮件服务器(Mail Server),它跟我们发送邮件一样,需要用户名和密码通过 SMTP(Simple Message Transfer Protocol)去连接邮件服务器。我们想让 SQL Server 来发送邮件,首先要告诉它用户名称,密码,服务器地址,网络传送协议,邮件服务器的端口。。。等信息。
  以下脚本实现了数据库邮件的配置:
--下面是具体的配置邮件步骤 
--在 sa 系统帐户下运行。 
--
--1. 启用 SQL Server 2005 邮件功能。 
use master
go
exec sp_configure 'show advanced options',1
go
reconfigure
go
exec sp_configure 'Database mail XPs',1
go
reconfigure
go
--2. 在 SQL Server 2005 中添加邮件帐户(account) 
exec msdb..sysmail_add_account_sp
        @account_name            = 'jgj'      -- 邮件帐户名称(SQL Server 使用)
       ,@email_address           = [email='jiaguijun@trusee.com']'jiaguijun@trusee.com'[/email] -- 发件人邮件地址
       ,@display_name            = null                      -- 发件人姓名
       ,@replyto_address         = null
       ,@description             = null
       ,@mailserver_name         = '203.86.70.229'           -- 邮件服务器地址
       ,@mailserver_type         = 'SMTP'                    -- 邮件协议(SQL 2005 只支持 SMTP)
       ,@port                    = 25                        -- 邮件服务器端口
       ,@username                = [email='jiaguijun@trusee.com']'jiaguijun@trusee.com'[/email] -- 用户名
       ,@password                = 'xxxxxx'      -- 密码
       ,@use_default_credentials = 0
       ,@enable_ssl              = 0
       ,@account_id              = null
--3. 在 SQL Server 2005 中添加 profile 
exec msdb..sysmail_add_profile_sp @profile_name = 'dba_profile'      -- profile 名称 
                                 ,@description  = 'dba mail profile' -- profile 描述 
                                 ,@profile_id   = null
-- 在 SQL Server 2005 中映射 account 和 profile 
exec msdb..sysmail_add_profileaccount_sp  @profile_name    = 'dba_profile' -- profile 名称 
                                         ,@account_name    = 'jgj'     -- account 名称 
                                         ,@sequence_number = 1             -- account 在 profile 中顺序 
--5. 利用 SQL Server 2005 Database Mail 功能发送邮件。 
exec msdb..sp_send_dbmail @profile_name =  'dba_profile'     -- profile 名称 
                         ,@recipients   =  [email='jiaguijun@trusee.com']'jiaguijun@trusee.com'[/email]  -- 收件人邮箱 
                         ,@subject      =  'SQL Server 2005 Mail 测