Xbasic

EMAIL_SEND2 Function

Syntax

Result_Flag as L = email_send2(P pMessage [,C profile [,L lSilent [,L store_in_mailbox [,L autowrap ]]]])

Arguments

pMessagePointer

A pointer variable containing the message.

FromCharacter

The sender's email address.

From_AliasCharacter

The sender's name.

ToCharacter

A semi-colon (;), comma (,), or CR-LF delimited list of recipients. Microsoft Outlook allows you to format the address as "recipient_name<[email protected]>". This hides the "<[email protected]>" portion of the field from the recipient.

CCCharacter

The CC list. Multiple entries are separated by commas.

BCCCharacter

The BCC list. Multiple entries are separated by commas.

SubjectCharacter

The subject line of the email. Optional, depending on mail server requirements.

MessageCharacter

The body of a text message. Optional, depending on mail server requirements.

Html_MessageCharacter

The body of a HTML message.

AttachmentsCharacter

A semi-colon (;), comma, or CR-LF delimited list of filenames. Any file type can be attached.

XmailerCharacter

Default = NULL. The sending email program.

LrelatedLogical

Default = .F. .T. = Attachments are embedded image in the HTML message. .F. = Attachments are separate files.

DateCharacter

Default = "". The date of the email.

FailureCharacter

Default = "". A list of failed addresses.

HeadersCharacter

Default = "". Optional email headers. Email headers are specified as a CR-LF delimited list of colon separated name-value pairs. Headers can be one of the standard mail headers or a user-defined header. Prefix user-defined headers with "X-".

dim headers as c =<<%str%
Reply-To: [email protected]
X-company: Example Co
X-campaign: Spring Launch
%str%

See RFC 822 to learn more about message headers.

The support of an email header is dependent on the email client. Some email clients may not support the header(s) you include in the message.
SuccessCharacter

Default = "". A list of successful addresses.

ReturnReceiptLogical

Default = .F. If .t. then an e-mail will be sent to the sender acknowledging that the recipient has read the e-mail. Note that not all e-mail clients support this feature and the recipient might decline to send the receipt.

profileCharacter

Uses the last active profile. The name of an email profile as found on the View > Settings > Email > Profiles tab.

lSilentLogical

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

store_in_mailboxLogical

Desktop Applications Only. Whether to store the message in your mailbox. .T. = Alpha Anywhere stores a copy of the message in a DBF table. .F. = Copy not saved.

autowrapLogical

Default = .T. Whether to force text emails to wrap at 72 characters per line. .T. = Automatically wrap all lines of text at 72 characters or less. .F. = Leave text email body unchanged.

Returns

Result_FlagLogical

Indicates success or failure after sending an email. If Result_Flag is .F., the email was not sent. If .T., the email was sent.

Description

Send an email message

In web applications EMAIL_SEND_NOPROFILE() is preferred because this function does not rely on an e-mail profile.
EMAIL_SEND2() 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_SEND2() sends an email message using Alpha Anywhere's built-in email features. The function does not require that you have a third party email client (such as Eudora or Outlook ) installed on the computer.

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 Alpha Anywhere outbox, a DBF table.

dim message as P
body = <<%a%
Just wanted to let you know that we really enjoy using Alpha Anywhere.
%a%
message.message = body
message.to = "[email protected]"
message.subject = "Thanks"
email_send2(message, "", .F., .T.)

The store_in_mailbox argument is not supported in web applications.

The Silent option is useful for Xbasic programmers who are using the EMAIL_SEND2() 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_SEND2() and set the Silent parameter to .T. .

Email_send2(message, profile, .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_sends()
end

Embedding Images in an Email 

This example shows how to include an image in an email. Note that pm.lrelated is set to .T.. This allows the image attached to the email to be referenced in the email body.

dim pm as p
pm.attachments = "C:\login.jpg"
pm.lrelated = .T.
pm.from = "[email protected]"
pm.from_alias = "Aaron Brown"
pm.to = "[email protected]"
pm.subject = "Inline Attachments"

pm.html_message = <<%html%
<html>
<head>
</head>
<body>
This is a message with an <img src="login.jpg" /><br>
inline image.
</body>
</html>
%html%

email_send2(pm)

Limitations

Desktop Applications Only

See Also