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

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Reference » System Procedures » System extended procedures » Extended system procedures for MAPI and SMTP

xp_startsmtp system procedure Next Page

xp_sendmail system procedure


Sends an email message.

Syntax

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 = file-name ]
[, 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 ]
)

Arguments

Some arguments supply fixed values and are available for use to ensure Transact-SQL compatibility, as noted below.

Permissions

DBA authority required

Must have executed xp_startmail to start an email session using MAPI, or xp_startsmtp to start an email session using SMTP.

If you are sending mail using MAPI, the content_type parameter is not supported.

Not supported on NetWare.

Remarks

xp_sendmail is a system procedure that sends an email message to the specified recipients once a session has been started with xp_startmail or xp_startsmtp. The procedure accepts messages of any length. The argument values for xp_sendmail are strings. The length of each argument is limited to the amount of available memory on your system.

The content_type argument is intended for users who understand the requirements of MIME email. xp_sendmail accepts ASIS as a content_type. When content_type is set to ASIS, xp_sendmail assumes that the message body ("message") is already a properly formed email with headers, and does not add any additional headers. Specify ASIS to send multipart messages containing more than one content type. See RFCs 2045-2049 ([external link] http://www.ietf.org/) for more information on MIME.

Attachments specified by the include_file parameter are sent as application/octet-stream MIME type, with base64 encoding, and must be present on the database server.

Return codes

See Return codes for MAPI and SMTP system procedures.

See also
Example

The following call sends a message to the user ID Sales Group containing the file prices.doc as a mail attachment:

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

The following sample program shows various uses of the xp_sendmail system procedure, as described in the example itself:

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