Sending SMTP Email

wwIPStuff easily supports sending email over the Internet. Two modes are supported: Synchronous where your application waits for the message being submitted to the server and receives a result code, or asynchronous where mail is sent in the background and control returns immediately to your application and no result message is returned. The latter is useful in Web applications for email confirmations and the like.

Regardless of the mode you use the syntax for using the mail functionality is the same:

LOCAL loSMTP as wwIPStuff loSmtp=CREATEOBJECT("wwIPStuff") loSmtp.cMailServer="mail.yourmailserver.net" loSmtp.cSenderEmail="rstrahl@west-wind.com" loSmtp.cSenderName="Rick Strahl" *** Optional Username * loSmtp.cUsername = "ricks" * loSmtp.cPassword = "secret" loSmtp.cRecipient="somebody@sweat.com,another@bust.com" loSmtp.cCCList="rstrahl@east-wind.com,looser@nobody.com" loSmtp.cBCCList="fred@flintstone.com" loSmtp.cSubject="wwIPStuff Test Message" loSmtp.cMessage="Who said this had to be difficult?" * loSmtp.cContentType = "text/html" && Optionally send HTML content * loSmtp.cAttachment="c:\temp\somefile.pdf,c:\temp\another.txt" && Optionally send file attachments llResult = loSmtp.SendMail() IF !llResult Wait window loSmtp.cErrorMsg ENDIF

You can also send messages Asynchronously:

*** Optionally send Asynchronous without waiting for a result loSmtp.SendMailAsync()

Note that when you send messages asynchronously, you get no result code or other indication whether the mail sending was a success.

Errors and Logging

Sending Emails can cause many errors on the server if your connection isn't configured properly or if you're not providing the right security information. Many common errors can pop up. In general when an error occurs wwIPStuff returns the SERVER ERROR MESSAGE. This is important - these errors typically have a 3 digit error code and a message associated with that is displayed in raw format. The messages give the server's reason for not accepting or failing the opeation. This error message is returned to you in the cErrorMsg property which you can check after the SendMail() call:

IF !loSmtp.SendMail() wait window loSmtp.cErrorMsg RETURN ENDIF

In addition to the error message you can also log the entire SMTP conversation with the server assuming you managed to connect in the first place. To see the session set the .cLogFileProperty to a filename that will act as your log file:

loSmtp.cLogFile = FULLPATH("SmtpLog.txt") llResult = loSmtp.SendMail()

The log might give further clues to why an SMTP session failed on the server.

See also

wwIPStuff::SendMail | wwIPStuff::SendMailAsync


  Last Updated: 1/18/2008 | © West Wind Technologies, 2008