Inbox and Outbox Manipulation in ASP - Receiving Email: Inbox
(Page 3 of 4 )
One of the most commonly asked questions on any ASP related forum is “How can I receive email thought CDONTS?” The simple answer is “You can use CDONTS.Session to receive email in your machine.” The SMTP (Simple Mail Transfer Protocol) Service handles standard SMTP messages, which are just text files that are transmitted between hosts using the SMTP. So, in theory, we can create, modify and read SMTP mail messages just as we would any other text file.
Inbox in Machine:
The first thing you need to do is to make sure that you have installed Microsoft's SMTP service, which you will find as part of the Windows NT 4 Option Pack. When you have completed the Option Pack installation you will find that, within your inetpub directory (along with WINNT directory), there will be a subdirectory called mailroot. Within this mailroot directory are various other subdirectories used for processing incoming and outgoing SMTP email. Pickup and Queue are used for the sending process, and Badmail is where anything that gets bounced by the remote server will end up, while Drop is where any incoming emails will appear.
The next thing that you need to do is to announce to the great wide world that this server in now accepting SMTP emails. For this purpose you have to associate it with a domain name. You can do this by adding records within your DNS system. One record is a MX record (MX means Mail Exchange). MX record tells other servers where to send your incoming SMTP emails. The sequence will be:
- First, MX keyword, which tells that it is Mail Exchange record.
- Second, Priority, it can be any integer number. Priority is useful in this sense that if your server went down, and main while emails come to your server, emails will be lost. So you can set some other servers and assign priorities to each. If height priority server is down, then server of next lower priority will be used for backup emails.
- Finally, Server, which will accept SMTP mails. Like mail.mydomain.com
For example: if your domain name is mydomain.com, the MX record will be:
MX 10 mail.mydomain.com
MX 20 mail.mydomain2.com
The next thing you need to do is set up the domain name in Default SMTP sites. To do this, open IIS, in the Default SMTP sits, Right-Click on Domains, and select New -> Domain. Then choose Local, and type your domain name. That is all that is required to set up your IIS configurations.
Now you can try to see whether it is working. For this purpose send an email to your domain, say me@mydomain.com. Now as I already said, all emails will come into the Drop directory of mailroot directory. So check the Drop directory; you will find new email with the extension EML. The file name will be any random number + .eml extension. You can double click on that file and see your received email. This email will be open in your default mail express. You can open it in Notepad and see the original message with all headers and source code.
We can also read messages by opening them as text files with the FileSystemObject. This may be useful for specific tasks where we are building applications that use email messages in the background to transfer information or send commands, without the messages being visible to the user in the normal way. By opening email file in this way you will also see some headers included in email. Such as:
Received: from 202.147.176.60 by by1fd.bay1.hotmail.msn.com with HTTP;
Thu, 22 Jan 2005 11:31:33 GMT
X-Originating-IP: [202.147.176.60]
X-Originating-Email: [abc@hotmail.com]
X-Sender: abc@hotmail.com
From: "My Name” abc@hotmail.com
You can code to filter these headers and show the original message to the user. And you can use any application for this purpose such as VB, C++ etc…
Next: Inbox using CDO >>
More ASP Code Articles
More By Burhan Khan