|
sql server提供了通过exchange或outlook收发邮件的扩展存储过程,下面将这几个过程简单的介绍一下。
一、启动sql mail
xp_startmail @user,@password @user和@password都是可选的
也可打开enterprise manager中的support services,在sql mail上单击右键打开右键菜单,然后按start来启动
二、停止sql mail
xp_stopmail
也可用上述方法中的菜单里的stop来停止
三、发送邮件
xp_sendmail {[@recipients =] 'recipients [;...n]'} [,[@message =] 'message'] [,[@query =] 'query'] [,[@attachments =] attachments] [,[@copy_recipients =] 'copy_recipients [;...n]' [,[@blind_copy_recipients =] 'blind_copy_recipients [;...n]' [,[@subject =] 'subject'] [,[@type =] 'type'] [,[@attach_results =] 'attach_value'] [,[@no_output =] 'output_value'] [,[@no_header =] 'header_value'] [,[@width =] width] [,[@separator =] 'separator'] [,[@echo_error =] 'echo_value'] [,[@set_user =] 'user'] [,[@dbuse =] 'database']
其中@recipients是必需的
参数说明:
参数 说明 @recipients 收件人,中间用逗号分开 @message 要发送的信息 @query 确定执行并依附邮件的有效查询,除触发器中的插入表及删除表外,此查询能引用任何对象 @attachments 附件 @copy_recipients 抄送 @blind_copy_recipients 密送 @subject 标题 @attach_results 指定查询结果做为附件发送 @no_header 不发送查询结果的列名 @set_user 查询联接的用户名,默认为guset @dbuse 查询所用的数据库,默认为缺省数据库
四、阅读邮件收件箱中的邮件
xp_readmail [[@msg_id =] 'message_number'] [, [@type =] 'type' [output]] [,[@peek =] 'peek'] [,[@suppress_attach =] 'suppress_attach'] [,[@originator =] 'sender' output] [,[@subject =] 'subject' output] [,[@message =] 'message' output] [,[@recipients =] 'recipients [;...n]' output] [,[@cc_list =] 'copy_recipients [;...n]' output] [,[@bcc_list =] 'blind_copy_recipients [;...n]' output] [,[@date_received =] 'date' output] [,[@unread =] 'unread_value' output] [,[@attachments =] 'attachments [;...n]' output]) [,[@skip_bytes =] bytes_to_skip output] [,[@msg_length =] length_in_bytes output] [,[@originator_address =] 'sender_address' output]]
参数说明:
参数 说明 @originator 发件人 @subject 主题 @message 信息 @recipients 收件人 @skip_tytes 读取邮件信息时跳过的字节数,用于顺序获取邮件信息段。 @msg_length 确定所有信息的长度,通常与@skip_bytes一起处理长信息
五、顺序处理下一个邮件
xp_findnextmsg [[@msg_id =] 'message_number' [output]] [,[@type =] type] [,[@unread_only =] 'unread_value'])
六、删除邮件
xp_deletemail {'message_number'}
如果不指定邮件编号则删除收件箱中的所有邮件
七、自动处理邮件
sp_processmail [[@subject =] 'subject'] [,[@filetype =] 'filetype'] [,[@separator =] 'separator'] [,[@set_user =] 'user'] [,[@dbuse =] 'dbname'] |