各位老大: 
        我在windows7+sql2005SP2环境下配置SQL邮件发送报错,  以下错误信息是从 
msdb.dbo.sysmail_event_log表中得知,整了一天没有搞定,不想重装SQL, 有没有那位老大知道, 请指教 1) Exception Information  ===================  Exception Type: System.NullReferenceException  Message: 未将对象引用设置到对象的实例。  Data: System.Collections.ListDictionaryInternal  TargetSite: Microsoft.SqlServer.Management.SqlIMail.Server.Objects.Account GetAccount(Int32)  HelpLink: NULL  Source: DatabaseMailEngine    StackTrace Information  ===================     在 Microsoft.SqlServer.Management.SqlIMail.Server.DataAccess.DataAccessAdapter.GetAccount(Int32 accountID)     在 Microsoft.SqlServer.Management.SqlIMail.Server.Controller.CommandFactory.CreateSendMailCommand(DBSession dbSession)     在 Microsoft.SqlServer.Management.SqlIMail.Server.Controller.CommandFactory.CreateCommand(DBSession dbSession)     在 Microsoft.SqlServer.Management.SqlIMail.Server.Controller.CommandRunner.Run(DBSession db)     在 Microsoft.SqlServer.Management.SqlIMail.IMailProcess.ThreadCallBack.MailOperation(Object o)

解决方案 »

  1.   

    为配置文件创建一个或多个数据库邮件帐户。有关创建数据库邮件帐户的详细信息,请参阅如何创建数据库邮件帐户 (Transact-SQL)执行存储过程 msdb.dbo.sysmail_add_profile_sp 以创建配置文件,要指定以下内容:要创建的配置文件的名称。
    配置文件的说明(可选)。
    对每个帐户执行 msdb.dbo.sysmail_add_profileaccount_sp,以将帐户添加到配置文件中。通过执行 msdb.sysmail_add_principalprofile_sp,向每个使用此配置文件发送邮件的数据库角色或用户授予访问配置文件的权限。使用数据库邮件配置向导或数据库邮件存储过程可以创建专用的数据库邮件配置文件,用于发送简单邮件传输协议 (SMTP) 邮件。专用配置文件可由用户或角色来使用。授予角色访问配置文件的权限可创建更易维护的体系结构。使用 Transact-SQL 创建数据库邮件配置文件
    为配置文件创建一个或多个数据库邮件帐户。有关创建数据库邮件帐户的详细信息,请参阅如何创建数据库邮件帐户 (Transact-SQL)执行存储过程 msdb.dbo.sysmail_add_profile_sp 以创建配置文件,要指定以下内容:要创建的配置文件的名称。
    配置文件的说明(可选)。
    对每个帐户执行 msdb.dbo.sysmail_add_profileaccount_sp,以将帐户添加到配置文件中。通过执行 msdb.sysmail_add_principalprofile_sp,向每个使用此配置文件发送邮件的数据库角色或用户授予访问配置文件的权限。示例
    以下示例将创建一个数据库邮件帐户和数据库邮件配置文件。然后,该示例将帐户添加到配置文件中,并向 msdb 数据库中的 DBMailUsers 数据库角色授予对该配置文件的访问权限。-- Create a Database Mail account
    EXECUTE msdb.dbo.sysmail_add_account_sp
        @account_name = 'AdventureWorks Administrator',
        @description = 'Mail account for administrative e-mail.',
        @email_address = '[email protected]',
        @replyto_address = '[email protected]',
        @display_name = 'AdventureWorks Automated Mailer',
        @mailserver_name = 'smtp.Adventure-Works.com' ;-- Create a Database Mail profile
    EXECUTE msdb.dbo.sysmail_add_profile_sp
        @profile_name = 'AdventureWorks Administrator Profile',
        @description = 'Profile used for administrative mail.' ;-- Add the account to the profile
    EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
        @profile_name = 'AdventureWorks Administrator Profile',
        @account_name = 'AdventureWorks Administrator',
        @sequence_number =1 ;-- Grant access to the profile to the DBMailUsers role
    EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
        @profile_name = 'AdventureWorks Administrator Profile',
        @principal_name = 'ApplicationUser',
        @is_default = 1 ;