Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

SMTP Client ActiveX component

0.00/5 (No votes)
24 Sep 2002 4  
An SMTP Client ActiveX component, that can be used in ASP, VC, VB, Excel etc.

Introduction

Smtp.Server is an ActiveX component that you may use to send emails. It may be used in Excel, ASP, VB, Visual C++ and other ActiveX container applications. (Please read the write up below for details on how to use Smtp.Server).

I made this component just for the fun of it. It is absolutely free, and like all free software, it has no guarantee and/or liability. Although I have tested it, I do not make any guarantees and accept liabilities (just saving my neck :-)).

Please read the complete document (given below), before reporting any bug(s) or giving your feedback.

Installation Instructions

Step (1):

Download source and EXE.

Step (2):

Once downloaded, double click SMTPServ.EXE. It is a self-extracting WinZip file. Unzip this file to the directory of your liking. Double click the newly unzipped file (SMTP.EXE). You should see a dialog box similar to the one given below:

Sample Image - smtp.gif

This indicates SMTP.Server has been successfully registered in the system Registry.

If you do not see this dialog box, please report the bug. (Remember that the application has not been tested on Win95/NT.)

Step (3):

Now, you are all set to use it in your Visual C++ applications (as CreateDispatch(�SMTP.Server�)), ASP/Excel/VB applications (as Server.CreateObject(�SMTP.Server�)).

Please go through the example code, and the methods/properties supported by SMTP.Server.

SMTP.Server Properties

SMTP.Server Methods

SMTP.Server Properties

  • LoginName

    Type: String.

    Default Value: �guest�.

    Description: Although the SMTP.Server does not require any user authentication, this parameter is given just for the heck of it! It's up to the user how he/she uses it. The only time when SMTP.Server uses this parameter is when it makes log entries. The LoginName will be written in the log entries so that you may identify the user whose mail was sent through the SMTP.Server. This may be a good tool for billing purposes. In a perfect world, the LoginName may be derived from MailFrom parameter. (normally MailFrom = LoginName@some.server.com, but there may be aliases and other mumbo jumbo that renders this technique, of determining the user, useless.)

    Back to top

  • Password

    Type: String

    Default Value: �guest�

    Description: SMTP.Server does not use this entry at all. This entry has been put there for saving the password. It's up to you to decide how you use it. Unlike LoginName, the Password is not entered in the log file. Why I put the password at all, is a mystery even to me. It's just that login name and password are like twins, so when I put the login name there (and for good reasons too, see the LoginName description), I automatically made an entry for Password.

    Back to top

  • MailTo

    Type: String

    Default Value: null

    Description: This property holds the destination email address. Only one destination address should be given here. If you want the email to be sent to multiple destinations, then use the CcTo property to specify other email addresses. You must set this property to a valid address before calling SendMail( ) method.

    Back to top

  • MailFrom

    Type: String

    Default Value: null

    Description: This property should be set with the sender�s address. If the sender�s address is not given, SMTP.Server checks the ReplyTo property. If ReplyTo property contains an email address, it will be used as the sender address. In case neither MailFrom nor ReplyTo is set, the system returns with an error �Invalid Sender address�.

    Back to top

  • SenderIP

    Type: String

    Default Value: �kashif.SMTP.Server�

    Description: This property should be set to the IP address of the machine that runs SMTP.Server component. If you do not set this property, it defaults to �Kashif.SMTP.Server�.

    Back to top

  • PortNumber

    Type: integer

    Default Value: 25

    Description: The default SMTP listening port is 25. You should not change this unless you have good reasons to do so.

    Back to top

  • ServerVersion

    Type: integer

    Default Value: 1

    Description: This is a read-only property. You cannot set its value. You can only retrieve its value.

    Back to top

  • SMTPServer

    Type: String

    Default Value: �mail.nexlinx.net.pk�

    Description: SMTP.Server does not deliver the email directly to the destination address specified in MailTo and CcTo properties. It passes on the email message to another server which in turn will send the message to the destination(s) on SMTP.Server�s behalf. It is similar to how other email clients (like Eudora, Exchange etc.) handle email delivery. You should specify the mail server�s IP address through the SMTPServer property. The server address could either be descriptive like �mail.nexlinx.net.pk� (my ISP�s mail server address) or an actual IP address like �202.59.64.7�. If you do not set this property, it defaults to �mail.nexlinx.net.pk�. I strongly recommend that you set this property to your own ISP/company�s mail server, since �mail.nexlinx.net.pk� probably has a policy to reject requests originating from domains other than �*.nexlinx.net.pk�.

    Back to top

  • EnableLog

    Type: boolean

    Default Value: 0 (FALSE) I.e., logs will not be maintained.

    Description: This property indicates to the SMTP.Server whether it should keep a log of all the Send Mail requests or not. If this parameter is set then the server will log complete communication to and from the destination SMTPServer (as mentioned in the parameter SMTPServer). You may use the log for billing purposes, to stop hacking, to debug the program etc. How you use it and why you need it, is completely up to you.

    See Also: LogFile

    Back to top

  • Property: LogFile

    Type: String

    Default Value: �C:\SMTPLog.txt

    Description: When you set the EnableLog parameter to true, SMTP.Server attempts to open the file as determined by the �LogFile� parameter. In case the file already exists, the server will start appending the log entries to it. If the file does not exist, the server will create a new file.

    Remember that the server only creates new file and not the directories. So, if you have set LogFile to �C:\logs\Smtp.txt� then make sure that the directory �c:\logs\� exists. If it does not exist then the server will discard the entry and will start appending in the default �C:\SMTPLog.txt� file. In case the file name is invalid, or the server could not create a file, it will start making log entries to the default file �C:\SMTPLog.txt�.

    You may enable logging and have a look at the generated log file, to see the syntax, and the level of information that the file maintains. You may use customized parsing scripts/programs that would parse the log file and implement your billing system, or to prevent spam, malicious emails etc. However, to make this meaningful, you should first set the LoginName parameter before calling the SendMail() method. See Example.asp for details:

    An excerpt from the log file is given below:

    BEGIN <Kashif> 
    Message intended for 4 addresses 
    HIM: 220 mail.nexlinx.net.pk ESMTP Nexlinx 
         Sendmail 8.9.3/8.9.3; Thu, 31 May 2001 14:09:01 +0500 
    ME: HELO kashif.SMTP.Server 
    HIM:250 mail.nexlinx.net.pk Hello [202.59.64.117], pleased to meet you 
    ME: MAIL FROM: <kashifmanzoor@giki.edu.pk> 
    HIM:250 <kashifmanzoor@giki.edu.pk>... Sender ok 
    ME: RCPT TO: <kashifmanzoor@hotmail.com> 
    HIM:250 <kashifmanzoor@hotmail.com>... Recipient ok 
    ME: RCPT TO: <kashifmanzoor@yahoo.com> 
    HIM:250 <kashifmanzoor@yahoo.com>... Recipient ok 
    ME: RCPT TO: <00030022@lums.edu.pk> 
    HIM:250 <00030022@lums.edu.pk>... Recipient ok 
    ME: RCPT TO: <naveedarshad@yahoo.com> 
    HIM:250 <naveedarshad@yahoo.com>... Recipient ok 
    ME: DATA 
    HIM:354 Enter mail, end with "." on a line by itself 
    ME: 
      Subject: This email comes to your courtesy of SMTP.Server 
      Reply-To: kashifmanzoor@giki.edu.pk 
      <55 bytes of message sent to the server> 
      . 
    HIM:250 OAA04529 Message accepted for delivery 
    Message Successfully delivered 
    ======== END ========

    There you have it! Use this log file as you please. The messages sent by SMTP.Server start with the ME tag, and the messages that are received by SMTP.Server start with the HIM tag. Every new log entry starts with a BEGIN tag and ends with END tag; however, if an error occurs while sending the mail, the END tag will not be present. So a missing END tag should indicate an error. To get the details of the error, simply see the corresponding HIM: line

    Back to top

  • Property: ReplyTo

    Type: String

    Default Value: null

    Description: This property should be set with the address at which you want the receiver to reply. If ReplyTo is not set, SMTP.Server automatically treats the address in MailFrom property as ReplyTo. This property is useful when the MailFrom address is different than ReplyTo; in case they are both the same, you may safely ignore ReplyTo.

    Back to top

  • Property: TimeOut

    Type: integer

    Default Value: 180 seconds (3 minutes)

    Description: This value specifies (in seconds) how long should the SMTP.Server take for a single email message. The timer starts when you call SendMail() method. If the SendMail() method does not return (with or without an error) within TimeOut seconds, SMTP.Server will forcibly abort the mail message. This safeguards your container applications from blocking after a call to SendMail().

    Back to top

  • Subject

    Type: String

    Default Value: �(no subject)�

    Description: This property holds the message subject. You can either set the mail subject through this property, or during the call to SendMail() as an input parameter. (See SendMail() method description.)

    Back to top

  • Message

    Type: String

    Default Value: null

    Description: This property holds the actual message. You can either set the message through this property or during the call to SendMail() as an input parameter. (See SendMail() method description.)

    Back to top

  • CcTo

    Type: String

    Default Value: null

    Description: In case your email is destined to multiple addresses, you can specify them through this property. To enter multiple addresses, separate them with a �,� (comma). E.g.: �abcd@efg.com, hij@klm.com, mno@pqr.com�. Note that every address except the last ends with a comma. SMTP.Server ignores any invalid addresses, and does not indicate any error. An invalid address could either be an address without an �@� in it, or an address list not separated by �,�. SMTP.Server, however, does remove any leading/trailing spaces from the addresses.

    Back to top

  • WMLOutput

    Type: boolean

    Default Value: 0 (FALSE) (i.e., output from SendMail() will not be compatible with the WML)

    Description: When you call SendMail() method, it returns a string that indicates the success or failure of the operation. This string may be used verbatim by your program to report the outcome of send mail process. However, if you are embedding SMTP.Server for sending email through a WAP (Wireless Application Protocol) device (e.g., your mobile phones, Handheld PCs etc.) then you must set this parameter to �1�. The reason is that the return message may contain illegal characters like angled brackets �<� or �>�. Although an HTML page may overlook these, a WML browser gets confused and tries to interpret it as a start/end of a WML tag, hence generating a serious �page cannot be displayed� error.

    Setting this property to �1� will ensure that the return message from SendMail() method is compatible with WML code (i.e., all the ambiguities are removed from the return string), and you may output the SendMail() return string directly to a WAP device. See Example WML Code.

    Back to top

  • SendMail (strCc, strSubject, strMessage, strAttachFile)

    SMTP.Server supports only one method (life doesn�t get any easier than this!). The parameters are pretty self explanatory.

    The method takes in the following parameters:

    • strCc: A string that holds the comma separated destination email addresses (see CcTo property).

    • strSubject: A string that holds the subject of the email message (see Subject property).

    • strMessage: A string that holds the actual message to be sent through email (see Message property).

    • strAttachFile: At the moment, SMTP.Server does not allow attachments to your messages. In the future versions, I will implement this feature, at which time this parameter will take in the attached file name. As of now, you may set it to an empty string or to any other value for that matter � SMTP.Server simply ignores it.

    You can either pass on the Cc/Subject/Message information directly through the SendMail() method call, or you can set these individually by accessing the properties directly. If you set these properties individually then make sure you call SendMail() method with empty strings as parameters. This is because the Subject/Cc/Message values passed directly as parameter to SendMail() call take precedence over any previously set values of Subject, CcTo, Message properties. (See Example ASP Code.) SendMail() method was slightly updated on Feb 15, 2002 in accordance to the feedback of Brian D Pearson.

    Return Value:

    The function returns a string that explains the outcome of the SendMail(). If the message is delivered successfully, the return string will contain �Message Successfully delivered�; else it will contain a description of any error that might have occurred.

    Back to top

Example Usage

Send bugs/feedback/criticism to: kashifmanzoor@hotmail.com.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here