Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » SQL Anywhere 服务器 - SQL 参考 » 系统对象 » 系统过程 » 按字母顺排序的系统过程列表

 

xp_sendmail 系统过程

发送电子邮件消息。

语法
xp_sendmail( 
 recipient = mail-address
 [, subject = subject ]
 [, cc_recipient = mail-address ]
 [, bcc_recipient = mail-address ]
 [, query = sql-query ]
 [, "message" = message-body ]
 [, attachname = attach-name ] 
 [, attach_result = attach-result ] 
 [, echo_error = echo-error ] 
 [, include_file = filename ] 
 [, no_column_header = no-column-header ] 
 [, no_output = no-output ] 
 [, width = width ]  
 [, separator = separator-char ] 
 [, dbuser = user-name ] 
 [, dbname = db-name ]  
 [, type = type ] 
 [, include_query = include-query ] 
 [, content_type = content-type ]
)
参数

一些参数提供固定值且可用来确保 Transact-SQL 兼容,如下所述。

  • recipient   此 LONG VARCHAR 参数指定接收者的邮件地址。当指定多个接收者时,必须用分号分隔每个邮件地址。

  • subject   此 LONG VARCHAR 参数指定消息的主题字段。缺省值为 NULL。

  • cc_recipient   此 LONG VARCHAR 参数指定 cc 接收者的邮件地址。当指定多个 cc 接收者时,必须用分号分隔每个邮件地址。缺省值为 NULL。

  • bcc_recipient   此 LONG VARCHAR 参数指定 bcc 接收者的邮件地址。当指定多个 bcc 接收者时,必须用分号分隔每个邮件地址。缺省值为 NULL。

  • query   此 LONG VARCHAR 参数与 Transact-SQL 一起使用。缺省值为 NULL。

  • "message"   此 LONG VARCHAR 参数指定消息内容。缺省值为 NULL。"message" 参数名需要用双引号括起来,因为 MESSAGE 是保留字。请参见保留字

  • attachname   此 LONG VARCHAR 参数与 Transact-SQL 一起使用。缺省值为 NULL。

  • attach_result   此 INT 参数与 Transact-SQL 一起使用。缺省值为 0。

  • echo_error   此 INT 参数与 Transact-SQL 一起使用。缺省值为 1。

  • include_file   此 LONG VARCHAR 参数指定附件文件。缺省值为 NULL。

  • no_column_header   此 INT 参数与 Transact-SQL 一起使用。缺省值为 0。

  • no_output   此 INT 参数与 Transact-SQL 一起使用。缺省值为 0。

  • width   此 INT 参数与 Transact-SQL 一起使用。缺省值为 80。

  • separator   此 CHAR(1) 参数与 Transact-SQL 一起使用。缺省值为 CHAR(9)。

  • dbuser   此 LONG VARCHAR 参数与 Transact-SQL 一起使用。缺省值为 guest。

  • dbname   此 LONG VARCHAR 参数与 Transact-SQL 一起使用。缺省值为 master。

  • type   此 LONG VARCHAR 参数与 Transact-SQL 一起使用。缺省值为 NULL。

  • include_query   此 INT 参数与 Transact-SQL 一起使用。缺省值为 0。

  • content_type   此 LONG VARCHAR 参数指定 "message" 参数的内容类型(例如,text/html、ASIS 等)。缺省值为 NULL。content_type 的值不经过校验;设置无效的内容类型导致发送无效或不可理解的电子邮件。

    如果要手动设置标头,则可将 content_type 参数设为 ASIS。执行此操作时,xp_sendmail 过程假定传递给消息参数的数据已经是带有标头的格式正确的电子邮件,且不添加任何附加标头。指定 ASIS 时,必须手动设置消息参数中的所有标头,也包括通常会通过将数据传递给其它参数而进行填充的标头。

权限

需要 DBA 权限

必须执行了 xp_startmail 才能使用 MAPI 启动电子邮件会话,或执行了 xp_startsmtp 才能使用 SMTP 启动电子邮件会话。

如果使用 MAPI 发送邮件,则不支持 content_type 参数。

注释

xp_sendmail 是一个系统过程,可在使用 xp_startmail 或 xp_startsmtp 启动了会话后,将电子邮件消息发送给指定的接收者。此过程接受任何长度的消息。xp_sendmail 的参数值为字符串。每个参数的长度受系统可用内存量的限制。

content_type 参数旨在用于那些了解 MIME 电子邮件要求的用户。xp_sendmail 接受 ASIS 作为 content_type。当 content_type 设置为 ASIS 时,xp_sendmail 假定消息主体 ("message") 是带有标头的格式正确的电子邮件,且不添加任何附加标头。指定 ASIS 以发送包含多个内容类型的多部分消息。有关 MIME 的详细信息,请参见 RFC 2045-2049 ([external link] http://www.ietf.org/)。

由 include_file 参数指定的附件将作为 application/octet-stream MIME 类型进行发送(采用 base64 编码),这些附件必须存在于数据库服务器上。

在 SQL Anywhere 10.0.0 及更高版本中,如果主题行含有非 7 位 ASCII 码的字符,系统会对 SMTP 电子邮件系统发送的邮件进行编码。此外,如果主题行含有非 7 位 ASCII 码的字符,电子邮件发送到具有 SMS 功能的设备时,可能无法正确解码。

返回代码

请参见MAPI 和 SMTP 系统过程的返回代码

另请参见
示例

以下调用向用户 ID 为 Sales Group 的用户发送一条包含文件 prices.doc (作为邮件附件)的消息:

CALL xp_sendmail( recipient='Sales Group',
      subject='New Pricing',
      include_file = 'C:\\DOCS\\PRICES.DOC' );

以下示例程序显示 xp_sendmail 系统过程的不同用法,如示例本身所述:

BEGIN
DECLARE to_list LONG VARCHAR;
DECLARE email_subject CHAR(256);
DECLARE content LONG VARCHAR;
DECLARE uid CHAR(20);

SET to_list='test_account@mytestdomain.com';
SET email_subject='This is a test';
SET uid='test_sender@mytestdomain.com'; 

// Call xp_startsmtp to start an SMTP email session
CALL xp_startsmtp( uid, 'mymailserver.mytestdomain.com' );

// Basic email example
SET content='This text is the body of my email.\n'; 
CALL xp_sendmail( recipient=to_list,
     subject=email_subject,
     "message"=content ); 

// Send email containing HTML using the content_type parameter,
// as well as including an attachment with the include_file
// parameter
SET content='Plain text.<BR><BR><B>Bold text.</B><BR><BR><a href="www.iAnywhere.com">iAnywhere 
 Home Page</a></B><BR><BR>';
CALL xp_sendmail( recipient=to_list,
     subject=email_subject,
     "message"=content,
     content_type = 'text/html',
     include_file = 'test.zip' ); 

// Send email "ASIS".  Here the content-type has been specified
// by the user as part of email body.  Note the attachment can
// also be done separately
SET content='Content-Type: text/html;\nContent-Disposition: inline; \n\nThis text 
 is not bold<BR><BR><B>This text is bold</B><BR><BR><a href="www.iAnywhere.com">iAnywhere Home 
 Page</a></B><BR><BR>';
CALL xp_sendmail( recipient=to_list,
     subject=email_subject,
     "message"=content,
     content_type = 'ASIS',
     include_file = 'test.zip' ); 

// Send email "ASIS" along with an include file.  Note that  
// "message" contains the information for another attachment
SET content = 'Content-Type: multipart/mixed; boundary="xxxxx";\n';
SET content = content || 'This part of the email should not be shown.  If this is shown 
 then the email client is not MIME compatible\n\n';
SET content = content || '--xxxxx\n';
SET content = content || 'Content-Type: text/html;\n';
SET content = content || 'Content-Disposition: inline;\n\n';
SET content = content || 'This text is not bold<BR><BR><B>This text is bold</B><BR>
 <BR><a href="www.iAnywhere.com">iAnywhere Home Page</a></B><BR><BR>\n\n';
SET content = content || '--xxxxx\n'; 
SET content = content || 'Content-Type: application/zip; name="test.zip"\n';
SET content = content || 'Content-Transfer-Encoding: base64\n';
SET content = content || 'Content-Disposition: attachment; filename="test.zip"\n\n';

// Encode the attachment yourself instead of adding this one in 
// the include_file parameter
SET content = content || base64_encode( xp_read_file( 'othertest.zip' ) ) || '\n\n';
SET content = content || '--xxxxx--\n'; 
CALL xp_sendmail( recipient=to_list,
      subject=email_subject,
      "message"=content,
      content_type = 'ASIS',
      include_file = 'othertest.zip' );

// End the SMTP session
    CALL xp_stopsmtp();
END