发送电子邮件消息。
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 提供此 INTEGER 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 0。
echo_error 提供此 INTEGER 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 1。
include_file 此 LONG VARCHAR 参数指定附件文件。缺省值为 NULL。
no_column_header 提供此 INTEGER 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 0。
no_output 提供此 INTEGER 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 0。
width 提供此 INTEGER 参数是为了与 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 提供此 INTEGER 参数是为了与 Transact-SQL 兼容。SQL Anywhere 不使用此参数。缺省值为 0。
content_type 此 LONG VARCHAR 参数指定 "message" 参数的内容类型(例如,text/html、ASIS 等)。缺省值为 NULL。content_type 的值不经过校验;设置无效的内容类型导致发送无效或不可理解的电子邮件。
要手动设置标头,请将 content_type 参数设置为 ASIS。执行此操作时,xp_sendmail 过程假定传递给消息参数的数据已经是带有标头的格式正确的电子邮件,且不添加任何附加标头。指定 ASIS 时,必须手动设置消息参数中的所有标头,也包括通常会通过将数据传递给其它参数而进行填充的标头。
此函数返回 INTEGER 状态代码。
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 功能的设备时,可能无法正确解码。
必须执行了 xp_startmail 才能使用 MAPI 启动电子邮件会话,或执行了 xp_startsmtp 才能使用 SMTP 启动电子邮件会话。
如果使用 MAPI 发送邮件,则不支持 content_type 参数。
您必须具有 SEND EMAIL 系统特权。
此示例通过 SMTP 发送纯文本消息。
CALL xp_startsmtp( 'doe@sample.com', 'corporatemail.sample.com' ); CALL xp_sendmail( recipient='jane.smith@sample.com', subject='This is my subject line', "message"='This text is the body of my email.\n' ); CALL xp_stopsmtp( ); |
此示例使用 SMTP 发送带有附件的 HTML 格式消息。
CALL xp_startsmtp( 'doe@sample.com', 'corporatemail.sample.com' ); CALL xp_sendmail( recipient='jane.smith@sample.com', subject='HTML mail example with attachment', "message"='Plain text.<BR><BR><B>Bold text.</B><BR><BR>' || '<a href="www.sap.com">SAP Home Page</a>', content_type = 'text/html', include_file = '\\temp\\sendmail2.sql' ); CALL xp_stopsmtp( ); |
此示例使用 SMTP 发送带有附件的内置 HTML 格式消息。
CALL xp_startsmtp( 'doe@sample.com', 'corporatemail.sample.com' ); CALL xp_sendmail( recipient='jane.smith@sample.com', subject='Inline HTML mail example with attachment', "message"='Content-Type: text/html;\nContent-Disposition: inline; \n\n' || 'Plain text.<BR><BR><B>Bold text.</B><BR><BR>' || '<a href="www.sap.com">SAP Home Page</a>', content_type = 'ASIS', include_file = '\\temp\\sendmail3.sql' ); CALL xp_stopsmtp( ); |
此示例使用 SMTP 发送带有一个签名和两个附件内置 HTML 格式消息,其中一个附件为 ZIP 文件。
BEGIN DECLARE content LONG VARCHAR; SET content = 'Content-Type: multipart/mixed; boundary="xxxxx";\n' || 'This part of the email should not be shown. If this ' || 'is shown then the email client is not MIME compatible\n\n' || '--xxxxx\n' || 'Content-Type: text/html;\n' || 'Content-Disposition: inline;\n\n' || 'Plain text.<BR><BR><B>Bold text.</B><BR><BR>' || '<a href="www.sap.com">SAP Home Page</a>\n\n' || xp_read_file( '\\temp\\johndoe.sig.html' ) || '--xxxxx\n' || 'Content-Type: application/zip; name="sendmail4.zip"\n' || 'Content-Transfer-Encoding: base64\n' || 'Content-Disposition: attachment; filename="sendmail4.zip"\n\n' || base64_encode( xp_read_file( '\\temp\\sendmail4.zip' ) ) || '\n\n' || '--xxxxx--\n'; CALL xp_startsmtp( 'doe@sample.com', 'corporatemail.sample.com' ); CALL xp_sendmail( recipient='jane.smith@sample.com', subject='Inline HTML mail example with signature and 2 attachments', "message"=content, content_type = 'ASIS', include_file = '\\temp\\sendmail4.sql' ); CALL xp_stopsmtp( ); END |
![]() |
使用DocCommentXchange讨论此页。
|
版权 © 2013, SAP 股份公司或其关联公司. - SAP Sybase SQL Anywhere 16.0 |