发送电子邮件消息。
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 兼容。SQL Anywhere 不使用此参数。缺省值为 NULL。
"message" 此 LONG VARCHAR 参数指定消息内容。缺省值为 NULL。"message" 参数名需要用双引号括起来,因为 MESSAGE 是保留字。
attachname 提供 LONG VARCHAR 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 NULL。
attach_result 提供 INT 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 0。
echo_error 提供 INT 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 1。
include_file 此 LONG VARCHAR 参数指定附件文件。缺省值为 NULL。
no_column_header 提供 INT 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 0。
no_output 提供 INT 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 0。
width 提供 INT 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 80。
separator 提供 CHAR(1) 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 CHAR(9)。
dbuser 提供 LONG VARCHAR 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 guest。
dbname 提供 LONG VARCHAR 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 master。
type 提供 LONG VARCHAR 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 NULL。
include_query 提供 INT 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 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 ( http://www.ietf.org/)。
由 include_file 参数指定的任何附件将作为 application/octet-stream MIME 类型进行发送(采用 base64 编码),这些附件必须存在于数据库服务器上。
在 SQL Anywhere 10.0.0 及更高版本中,如果主题行含有非 7 位 ASCII 码的字符,系统会对 SMTP 电子邮件系统发送的邮件进行编码。此外,如果主题行含有非 7 位 ASCII 码的字符,电子邮件发送到具有 SMS 功能的设备时,可能无法正确解码。
以下调用向用户 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 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 |
![]() |
使用DocCommentXchange讨论此页。
|
版权 © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |