wwipstuff::sendmail

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

To send email set various property values and send the actual message. The following properties can be set.

cMailServer
The IP Address or domain name of the SMTP server that is responsible for sending the message. The server must support 'pure' SMTP mail services and must not require a login prior to sending messages.

cSendername
Display name of the person sending the message. This option is often overridden by the mail server with the actual user account, but some servers leave the name as set here.

cSenderEmail
The sender's Email address.

cRecipient
Either a single recipient email address or a list of comma delimited addresses. Limited to 1024 characters. To specify a name and email address use the following syntax (works for all Recipient and CC properties):
Joe Doe <jdoe@yourserver.com>

cCCList
Either a single CC recipient email address of a list of comma delimited addresses. Limited to 1024 characters.

cBCCList
Blind CCs are sent messages but do not show on the recipient or CC listing of the receiver. Limited to 1024 characters.

cSubject
The message subject or title.

cMessage
The actual message body text.

cAttachment
The name of the file that is to be attached to the message. This property must be filled with a valid path pointing at the file to attach. Multiple files can be attached by separating each file with a comma.

cContentType
Content type of the message allows you to send HTML messages for example. For HTML set the content type to text/html. Content types only work with text content types at this time since special encoding of the message text is not supported. All binary types should be sent as attachments.

cUsername, cPassword
If you are sending mail to a mail server that requires username and password authentication, set these properties. Only unencrypted, plain text communication is supported using the AUTH LOGIN command.

o.sendmail()

Return Value

.T. or .F. When .F. check cErrorMsg for error string.

Parameters

It's highly recommended you use the class property interface rather than the parameter interface. The parameter interface is still there, but no longer documented. See example.

Remarks

To check for errors check the return value of the SendMail method. If the value is .F. check the cErrorMsg property for the error message.

If you're sending plain text messages separate paragraphs with CHR(13) + CHR(10). Remember that if you send HTML you will need <br> and <p> tags to separate your lines (or use DisplayMemo() from wwUtils).

SendMail works with pure SMTP servers and most ESMTP servers. However, some servers that don't properly support these interfaces may cause problems.

SendMail does not support SSL based emails, and does not support encrypted authentication (only base64 encoded default authentication).

Common Problems

Due to email's potential as a weapon there are scenarios where mail servers and your computer might get in the way of sending emails.

Relay Errors
Relay errors occur on the server and usually tell you that relaying is not supported or that your IP Address to send from is invalid for this server. Most mail servers these days do not allow sending email except from their specific set of known local domains. If you use their servers from an IP that is not in a known block (such as when you're travelling or have otherwise 'roaming' IP addresses), you will get an error. Most mail servers support Authentication which you can use by setting the cUsername and cPassword properties, or by first logging into the associated POP3 server with a user name and password (which you can do with the wwPop3 class).

Anti-Virus Software or Firewall blocking
Because of security concerns in today's software there are many ways that email from a typical client machine can be blocked. Make sure that your (or your client's) Windows Firewall is set up to allow access for your application through port 25 which is the default SMTP port (or whatever other port you might be explicitly using). Some Anti-Virus software like McAffee also monitors TCP/IP ports in use and requires that you configure each application that uses a specific port.

Example

o=CREATEOBJECT("wwIPStuff")

o.cMailServer="mail.yourmailserver.net"
o.cSenderEmail="rstrahl@west-wind.com"
o.cSenderName="Rick Strahl"

*** Optional Authentication Log in
o.cUsername = "ricks"
o.cPassword = "password"

o.cRecipient="somebody@sweat.com,another@bust.com"
o.cCCList="rstrahl@east-wind.com,looser@nobody.com"
o.cBCCList="fred@flintstone.com"
o.cSubject="wwIPStuff Test Message"
o.cMessage="Who said this had to be difficult?"
o.cAttachment="c:\config.sys,c:\utl\hex.exe"

*** Optionally send HTML formatted messages
*** if your content is HTML
* o.cContentType="text/html"

*** Send and don't wait for completion
*? o.SendMailAsync()   

*** Send again - wait for completion
llResult = o.SendMail()       
IF !llResult
   Wait window o.cErrorMsg
ENDIF

See also:

Class wwipstuff | wwIPStuff::SendMailAsync


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