wwSMTP::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.

There's no feedback on success or failure when this method is used. The method always returns .T. but there's no guarantee that the SendMail operation actually worked or even reached the server.

o.SendMailAsync()

Remarks

Background Threads

The send operation occurs on a separate thread in .NET. If you shut down your application while SendMail operations are still pending on these background threads it's likely that application will crash. Therefore be sure you allow some time before shutdown to allow mail requests to finish.

Too many Threads

Please be careful using this function to send many simultaneous messages. Async operations can be queued up very, very quickly. For example if you run 1000 async mail requests in a tight for loop those requests will execute in a couple of seconds, however behind the scenes there will now be 1000 simultaneous threads executing vying for bandwidth and system resources.

This method should be used in moderation only to shoot off one or a few messages asynchronously only. For full batch operations it's better to run the synchronous version for stability but also for the ability to detect and log failures properly.

Example

DO wwSmtp 
LOCAL loSmtp as wwSmtp
loSmtp = CREATEOBJECT("wwSmtp")

*loSmtp.cMailServer = "Localhost"
loSmtp.cMailServer = "smtp.gmail.com:587"
loSmtp.lUseSsl = .T. && Google requires TLS

*** Optional authentication if server requires it
loSmtp.cUsername = "ricks"
loSmtp.cPassword = "secret"

loSmtp.cSenderName= "West Wind Tools"
loSmtp.cSenderEmail = "admin@test.com"

loSmtp.cRecipient = "rickstrahl@hotmail.com,admin@mydomain.com"
loSmtp.cCcList = "admin2@mydomain.com,admin@monitor.com"

*** Optional - custom content type - text/plain by default
loSmtp.cContentType = "text/html"

loSmtp.cSubject = "Test Message through Google"
loSmtp.cMessage = "<b>Test message from wwsmtp, to check out how this operation works.</b>"

*** Optionally attach files
loSmtp.cAttachment = "c:\rick4453.jpg,c:\sailbig.jpg"

*** Optional - a couple of options
loSmtp.cReplyTo = "james@cranky.com"
loSmtp.cPriority = "High"

*** Send it
loSmtp.SendmailAsync()

*** Message is only queued on thread so no useful result
*** or error information is available
? "Done..."

See also:

Class wwSMTP

© West Wind Technologies, 1996-2018 • Updated: 11/29/16
Comment or report problem with topic