Using the SendEmail( ) functionThis function is used to send all the emails throughout the site - so it's the only place that cares what email system you are using. Currently, 3 components are supported, but I'll support whatever else you ask for, within reason! Microsofts' "Collaboration Data Objects for Windows NT Server", commonly known as CDONTS. Persits' ASPEmail component. ServerObjects' ASPMail component. Dimac's w3 JMail component. The email component to use is specified by the nEmailServer setting in include/config.asp. Using CDONTS// get a mail object
oMail = Server.CreateObject ( "CDONTS.NewMail" );
// setup the mail
if ( sFromEmail == "" )
oMail.From = 'Anonymous';
else
oMail.From = sFromEmail;
var sEmailList = sToEmail.split ( /[\s;,]/ );
var nEmail;
var sMail = '';
for ( nEmail in sEmailList )
sMail += sEmailList [ nEmail ] + ';';
oMail.To = sMail;
sEmailList = sBccEmail.split ( /[\s;,]/ );
sMail = '';
for ( nEmail in sEmailList )
sMail += sEmailList [ nEmail ] + ';';
oMail.Bcc = sMail;
oMail.Importance = 1;
// if you want HTML mail...
// uncomment the next two lines
// oMail.BodyFormat = 0;
// oMail.MailFormat = 0;
// if you want to add an attachment...
// uncomment the next line
// oMail.AttachFile ( 'c://autoexec.bat' );
oMail.Subject = sSubject;
oMail.Body = sBody;
// send it
oMail.Send ( );
|
Sending a simple email is very easy. This is literally the only code I've ever used. Start by creating an instance of the CDONTS.NewMail object, then fill in the relevant properties and call the Send( ) method. Some things to note though: In order to specify multiple To, Cc or Bcc recipients of a message, simply separate the addresses with a semicolon... oMail.To = '[email protected];[email protected];[email protected]' Although the documentation says that you can send in an optional caption to the AttachFile method, it's never worked for me! After the call to Send( ), the object is invalid. Do not try to use it again - you must create a new object. Part 5: Using JMail...
|