Xbasic

EMAIL_SEND Function

Syntax

Result as N = email_send(C send_to ,C subject ,C message [,C attachments [,C cc [,C bcc [,L store_in_outbox [,C text_type [,C html_message [,C profile[,L zip_attach [,L lSilent [,L returnReceipt ]]]]]]]]]])

Arguments

send_toCharacter

One or more comma delimited addresses.

subjectCharacter

The subject of the message.

messageCharacter

The contents of the message.

attachmentsCharacter

A ";", comma, or CR-LF delimited list of filenames to attach to the message. If multiple attachments are specified, Alpha Anywhere will automatically zip the attachments into a single file. Any file type can be attached.

ccCharacter

One or more comma delimited addresses.

bccCharacter

One or more comma delimited addresses.

store_in_outboxLogical

.T. = Alpha Anywhere stores a copy of the message in the Alpha Anywhere outbox (typically A_EMAIL.DBF in the program folder). .F. = Copy not saved.

When sending email from the Server only version of the Application Server, set this value to .F.
text_typeCharacter

Default = "" (plain text). "" (Null) = plain text email, "HTML" = HTML email.

html_messageCharacter

The contents of the message in HTML format.

profileCharacter

The name of your email profile as found on the View > Settings > Email > Profiles tab.

When sending email from an ISP's server, you must specify your profile.
zip_attachLogical

Default = .T. .T. = Attachments are zipped into a single file. .F. = Attachments are individual files.

lSilentLogical

Default = .F. Allows you to trap errors using the Xbasic ON ERROR GOTO command. .T. = Error trapping on. .F. = Error trapping off.

returnReceiptLogical

Default = .F. Allows you to specify a request a return receipt.

Returns

ResultNumeric

Result is 0 if the email was not sent, and 1 if the email was sent.

Description

Sends an e-mail using the built-in, Alpha Anywhere e-mail feature. Set text_type to "html" for HTML email. If lSilent = .T., email_send will throw an error rather than show a message box.

In web applications EMAIL_SEND_NOPROFILE() is preferred because this function does not rely on an e-mail profile.
EMAIL_SEND() requires that you have configured an Alpha Anywhere email profile. If you are working in an environment where this is not possible, use EMAIL_SMTP_OPEN(), EMAIL_SMTP_SEND(), and EMAIL_SMTP_CLOSE().
EMAIL_SEND() is a high level wrapper for EMAIL_SEND2(), which exposes more options for the developer and may be easier to use.

EMAIL_SEND() sends an email message using Alpha Anywhere's built-in email features. It does not require a third party email client (such as Eudora, or Outlook.)

If Text_Type is "HTML" and Message and HTML_Message are both specified, Message is treated as the plain text version and HTML_Message is treated as the HTML version. In this case, both the plain text version and the HTML version are sent together in the same email. Email clients that support HTML text will see the HTML version and those that do not will see the plain text version.

If HTML_Message is not specified and Text_Type is "HTML," message is treated as the HTML text.

EMAIL_SEND() is not sensitive to the type of image files attached and embedded in HTML formatted messages.

Example

Sends an email message using Alpha Anywhere's internal email facility. A copy of the message is stored in the user's AlphaAnywhere outbox.

body =<<%a%
Just wanted to let you know that we really enjoy using Alpha Anywhere.
%a%
email_send("[email protected]","Thanks",body,"","","",.T.)

The Silent option is useful for Xbasic programmers who are using the email_send() function in a loop where they want to prevent the standard Alpha Anywhere error messages from popping up when an error (such as a bad email address) in encountered. Instead, they want to write their own error handler for this condition. For example:

Dim tbl as P
Dim ITbl as P
Tbl = table.open("customers")
Query.filter = "balance> 1000000"
Query.order = "recno() "
ITbl = tbl.query_create()
Tbl.fetch_first()
While .not. tbl.fetch_eof()
 ON ERROR GOTO BAD_EMAIL

Fill in all of the arguments for EMAIL_SEND() and set the Silent parameter to .T..

Email_send("...", .t.)
 ON ERROR GOTO 0 'turn error handler off
 Tbl.fetch_next()
End While
Tbl.close()
'end the main script here so that it does not continue into the error handler
End
BAD_EMAIL:
'put you own error handling code here
RESUME NEXT
'causes Alpha Anywhere to resume on the line after email_send()
end
This method is not supported in Alpha Cloud. Use EMAIL_SEND_NOPROFILE() or EMAIL_SEND_SPARKPOST() instead.

See Also