Class wwSmtp

The wwSMTP class allows sending emails from Visual FoxPro applications through standard SMTP/ESMTP mail servers. In order to use this class you will need to have an SMTP mail server address from your or your users ISP or a company server.

Two modes: Classic or wwSmpt (.NET)

The wwSmtp class comes in two flavors:

  • .NET Mail Mode (nMailMode = 0)
    Uses .NET and wwDotNetBridge to send emails. The .NET component provides additional features such as SSL/TSL encrypted content, embedded rich content resources like images and the ability to send multiple emails on a single mail connection. The .NET interface uses the native SmtpClient in .NET to abstract mail sending operations which are exposed through wwDotNetBridge.

  • Classic wwIPStuff Mode (nMailMode = 2)
    Uses classic wwIPStuff behavior using a plain Win32 dll that doesn't need to be registered nor require any special runtimes. Only supports SendMail and SendMailAsync methods - the Connect/SendMessage/Close methods that allow for single connection multi-recipient sends are not available. This is the default behavior.

nMailMode can be set via property:

loSmtp = CREATEOBJECT("wwSmtp")
loSmtp.nMailMode = 0 && .NET mode

or via Init parameter:

loSmtp = CREATEOBJECT("wwSmtp",0)
Custom
  wwSmtp

Remarks

Running wwSmtp off a Network

If you're running wwSmtp in .NET mode and from a network location please take a look at .NET security configuration required that might affect operation of the wwSmtp class.

Dependencies:
  • wwDotnetBridge.prg
  • wwUtils.prg
  • wwApi.prg
  • wwCollections.prg
For .NET mode
  • .NET Runtime 4.5 or later
  • wwDotNetBridge.dll
  • wwIpStuff.dll
For Classic Mode
  • wwIPStuff.dll

Class Members

MemberDescription

AddAlternateView

Allows adding an alternate view of the message that provides richer content. For example you may configure the main message as plain text and the alternate view as html including embedded images that are stored as part of the message.

o.AddAlternateView(loAlternateView)

AddAttachment

Adds one or more file attachments to the mail message.

o.AddAttachment(lcFileName, lcContentType)

AddHeader

Adds an SMTP header to this email request using a key value pair.

o.AddHeader(lcHeader, lcValue)

ClearAttachments

Clears any attachments previously added with AddAttachment().

o.ClearAttachments()

Close

Closes an SMTP connection opened with Connect

o.Close()

Connect


wwSmtp :: Connect

o.Connect()

Dispose

Cleans up this object instance by removing the .NET SMTP reference and wwDotNetBridge instance. Can be called explicitly, but is also called internally off the object's Destroy() event.

o.Dispose()

SendMail

This method allows sending of SMTP emails which is the most common Email interface for the Internet. This method requires that you have access to an SMTP mail server.

o.SendMail()

SendMailAsync

This method functions identical to the SendMail method of this component, except that the message is sent asynchronously in the background while the call to this function immediately returns to FoxPro.

o.SendMailAsync()

SendMessage

Sends a single message to an SMTP server, but allows multiple messages to be sent on a single open SMTP connection. Requires that you call Connect() before SendMessage() calls and Close() or Dispose() after.

o.SendMessage(lcRecipient, lcCC, lcBcc)

cAlternateContentType

Content type of alternate text sent. Defaults to text/plain for plain text.

cAlternateText

Allows you to specify an alterate message format. Commonly used to send a plain text message in addition to an HTML message for clients that don't support HTML.

cAttachment

One or more attachments, in a comma delimited list. Files need to be specified as fully qualified files including paths.

cBccList

List of Blind CCs. Comma delimited

cCCList

List of CC's. Comma delimited

cContentType

The content type of the message to send. Defaults to text/plain.

cErrorMsg

An error message if the SendMail, SendMailAsync, SendMessage request fails.

cMailServer

Specifies the mail server's IP Address or domain name. A port name can be appended with a colon and portnumber (smtp.mydomain.com:587).

cMessage

The body for the message to send.

cPassword

Most mail server's these days require authentication and this property specifies the password.

cPriority

The priority of the message to send.

cRecipient

One ore more recipients. Multiple recipients should be comma or semi-colon delimited.

cReplyTo

The Reply-To address that is used when the user clicks on Reply in the mail client. By default this value is not provided and the reply to button simply replies to the sender.

cSenderEmail

The sender's email address that displays in the mail client's sender information.

cSenderName

The display name of the sender that displays in the mail client's Sender display. Optional.

cSubject

The title or subject header for the message to send. This message should be provided in plain text (ie. no formatting or HTML markup for HTML messages).

cUserAgent

The user agent (x-mailer header) that is sent with the email request. Defaults to West Wind Smtp X.0 where X is the major version number.

cUsername

Username used for authentication. Most mail server's these days require authentication and this property specifies the user name.

lError

True if a method call fails

lReturnReceipt

Determines if a return receipt is requested (Return-Receipt-To)

lUseSsl

Determines if a secure connection using SSL/TLS should be used for this mail request.

nMailMode

Determines what underlying technology is used to send emails

nServerPort

The port on which to send email. Can also be overridden in the cMailServer string by appending a : and port number.

nTimeout

The timeout in seconds before mail sending is considered to have failed.

oSmtp

An instance of the Westwind.wwSmtp .NET component.

Example

DO wwSmtp && load libraries

LOCAL loSMTP as wwSmtp
loSmtp=CREATEOBJECT("wwSmtp")
loSmtp.nMailMode = 0  && wwIPStuff mode (Win32 - default)   0 - .NET wwSmtp

loSmtp.cMailServer="mail.yourmailserver.net"
loSmtp.cSenderEmail="rstrahl@mydomain.com"
loSmtp.cSenderName="Mr. Testa"

*** Optional Username
* loSmtp.cUsername = "ricks"
* loSmtp.cPassword = "seeKrit"

*** Optional SSL Messages (only in .NET mode (nMailMode = 0))
* loSmtp.lUseSsl = .T.

loSmtp.cRecipient="somebody@sweat.com,another@bust.com"
loSmtp.cCCList="rstrahl@east-wind.com,looser@nobody.com"
loSmtp.cBCCList="fred@flintstone.com"
loSmtp.cSubject="wwSmtp Test Message"

*** Optionally specify content type - text/plain is default
loSmtp.cContentType = "text/html"  
loSmtp.cMessage="Who said this had to be <b>difficult</b>?"

*** Optionally provide an alternate content type or plain text fallback
loSmtp.cAlternateContentType = "text/plain"
loSmtp.cAlternateText = "Plain text can go here."

*** Optionally send file attachments
loSmtp.AddAttachment("c:\temp\somefile.pdf")
oSmtp.AddAttachment("c:\temp\sailbig.jpg")

llResult = loSmtp.SendMail()      

IF !llResult
   Wait window loSmtp.cErrorMsg
ENDIF

Requirements

Assembly: wwsmtp.prg

See also:

Sending SMTP Email | Sending Messages with Html and Text body | wwSMTP::SendMail |

© West Wind Technologies, 1996-2024 • Updated: 05/26/24
Comment or report problem with topic