It's become apparent that someone visiting your Web site or speaking to you on the phone may not give you the correct e-mail address. For good reasons people are wearing of giving out their e-mail address. I personally thank Microsoft for filtering in Outlook, since every day I get about 100 junk e-mails. I laugh all the way to the deleted folder, as they are instantly deleted. Also it's just possible that a typo can occur while gathering data. Looking at the issue from a sales and marketing perspective it's very important to collect valid information, even if it is syntactically correct. It's now possible to connect to users' mail servers and ask if they are valid or not.
First we can validate an e-mail address syntactically. We can check for a "@" and the "." characters in an e-mail address. Unfortunately this doesn't help when I download software or a demo, and I use JohnNOWAY@aol.com. This guy's probably bitter about getting some of the SPAM that was meant for me.
So what are some solutions to this problem? One way is to have the visitor wait for an e-mail with a password or link that allows them to gain access to your resource. However, if you are just collecting information for marketing purposes, the user has no incentive to complete the process.
A more reasonable solution is simply to ask the user's mail server if his address is valid. I tried for days to write this code in Visual Basic 6. I tried using several socket controls to connect to the mail server. I even tried calling the WIN API natively. The socket controls were expensive and flaky. Calling the WIN API from VB was a little better; I still experienced blocking and unreliable results. For weeks I tired trying to make some progress but ultimately did not succeed.
The problem did not go away by itself, and I was eventually forced to revisit the issue. However, this time I would use my new tool, Visual Studio .NET. First I searched the newsgroups looking for some ideas. Then I spent about 45 minutes prototyping and was ready to go. Let's take a look at what I came up with.
First things first. We still want to ensure that the e-mail address is syntactically correct. I'm going to assume you know how to do this. If you don't, you can find some validation controls in ASP.NET. Next we want to ensure that the domain is valid. If someone provides us with the domain BeenSwindled@SPAMMASTERS.COM, we want to check to make sure spammasters.com is valid before we try to connect to it.
We are going to launch a command shell to do a "Name Server" lookup. Every domain name has, or at least should have, an MX record which points e-mail servers to the correct server that handles e-mail for that domain. So we are simply asking the DNS server for the mail server of the supplied domain. I wouldn't dare try this in Visual Basic, but in .NET it works like a charm.
We use a REG expression to find the mail exchanger server value. The Matched pattern returns to us the value after mail exchanger.
Private Function NSLookup(ByVal sDomain As String) As String
Dim info As New ProcessStartInfo()
Dim ns As Process
info.UseShellExecute = False
info.RedirectStandardInput = True
info.RedirectStandardOutput = True
info.FileName = "nslookup"
info.Arguments = "-type=MX " + sDomain.ToUpper.Trim
ns = Process.Start(info)
Dim sout As StreamReader
sout = ns.StandardOutput
Dim reg As Regex = New Regex("mail exchanger = (?<server>[^\\\s]+)")
Dim mailserver As String
Dim response As String = ""
Do While (sout.Peek() > -1)
response = sout.ReadLine()
Dim amatch As Match = reg.Match(response)
If (amatch.Success) Then
mailserver = amatch.Groups("server").Value
Exit Do
End If
Loop
Return mailserver
End Function
If we determine that the mail sever is bogus, we don't need to go any further. We can simply ask them to double check their e-mail address.
If the domain is valid, then we can connect to it. Our goal here is to connect to the mail server as if we are sending our first e-mail to the visitor of our Web site. If the mail server tells us that the user is invalid or doesn't exist, then we'll know we have a bad address.
This process works by creating a socket to the mail server and communicating with it in its native tongue. Notice how polite we are by saying HELO. Watching mail servers talk to each other is very interesting. One late night I thought I saw two mail servers engaging in an actual conversation. Well maybe I was just working too hard. Anyway, let's not share all the fun.
This next step requires a valid domain name for telling the other mail server who we are. We need to tell them that we are projectthunder.com or a valid domain. Depending on how busy your application is, you may want to adjust the timeout setting here as well. For this example we are waiting up to three seconds for responses. If you lower the setting more failures will occur depending on network load. These are timeout failures. Not all e-mail servers are as snappy as we might like. An error doesn't mean the address is bad, but it doesn't mean it's good either.<<-This sentence isn't saying anything. In these cases you may want to keep a field open for setting a status of an e-mail, maybe come back with a background process and validate the e-mail later. The ideal time-out would be 30 seconds for a batch process to update statuses later. If the address fails twice at different times, it is likely a bad address.
<WebMethod()> Public Function ChatMailServer(ByVal sEmail As String) As Long
Dim oStream As NetworkStream
Dim sFrom As String
Dim sTo As String
Dim tResponse As Integer
Dim ConnectUP As Integer
Dim sResponse As String
Dim iResponse As Integer
Dim sToSend As String
Dim Remote_Addr As String
Dim mserver As String
Dim sText As String()
sTo = "<" + sEmail + ">"
'separate domain name from user name
sText = sEmail.Split(Ctype("@",Char))
mserver = NSLookup(sText(1))
'If mail server is blank then fail
If mserver = "" Then
Return 4
Exit Function
End If
'Needs to be a valid domain name
Remote_Addr = "projectthunder.com"
sFrom = "<myIP@" & Remote_Addr + ">"
'Create Object as late as possible
Dim oConnection As New TcpClient()
Try
'Set connection based on load
oConnection.SendTimeout = 3000
'Connecting on SMTP port
oConnection.Connect(mserver, 25)
'Get Stream from Mailserver
oStream = oConnection.GetStream()
'Collect Response
sResponse = GetData(oStream)
sResponse = TalkToServer(oStream, "HELO " & Remote_Addr & vbCrLf)
sResponse = TalkToServer(oStream, "MAIL FROM: " & sFrom & vbCrLf)
If ValidResponse(sResponse) Then
sResponse = TalkToServer(oStream, "RCPT TO: " & sTo & vbCrLf)
If ValidResponse(sResponse) Then
Return 1
Else
Return 2
End If
End If
TalkToServer(oStream, "QUIT" & vbCrLf)
oConnection.Close()
oStream = Nothing
Catch
Return 3
End Try
End Function
Depending on the code that is returned, we'll have an idea of the status of our e-mail address. This script returns different codes depending on what was possible. If "1" is returned, then it's good. If "2" is returned, then we know that the domain was good, but the user name wasn't valid. If "4" was returned, an error occurred.Conclusion
If someone does input a malformed e-mail address, maybe you can display a screen with your privacy statement to try to earn their trust. If you are going to sell their e-mail address, then use this information to at least know that the e-mail may not be valid. This can save your bandwidth from sending e-mails that will get lost in cyberspace.
It is also good to note that you should comply with the few electronic e-mail laws on the books. It's always good to include a link in the e-mail to allow people to unsubscribe from your list. If your organization is reported too many times, there are private organizations that will black-list your domain name. Many e-mail servers are referencing these black-lists and ignoring mail from them. So happy spamming... I mean e-mail responsibly!!!
This article has a sample Web service that exposes a method for validating e-mail in this manner. There is also a sample form that references the web service and consumes it.
Calvin Luttrell has consistently utilized his knowledge of Microsoft
Solutions to streamline projects such as the Web site for the Golden Globes
to various CRM integrated systems currently running across the country.
Prior to joining 1-800-DENTIST as a Senior Software Architect, Luttrell
served as a Senior Support Engineer at GoldMine Software, a position in
which he accredits his vast knowledge and experience in working effectively
in all facets of development from communication to software architecture.
Aside from 1-800-DENTIST, Luttrell also provides development consultation
and training for small-to-medium consulting companies. He is currently
working on ProjectThunder.com, a future project concerning effective team
management and how to increase production results within the Thunder
Framework (which runs on DOT NET). Luttrell can be reached at
Calvin@projectthunder.com.
Free SMTP component that supports multiple file attachments, unlimited recipients, CC's, BCC's and REPLY-TO's. Sends messages as plain text or in the HTML format. Premium features include message queuing and deferred processing for high mail volumes. When used with AspEncrypt, generates S/MIME-enabled secure mail.
AspMail supports multiple file attachments (MIME and UUE), US ASCII and ISO-8859-1 character sets, 8bit subject lines, custom message content headers, custom message headers, MS Exchange priority headers, PGP and more.
DevMailer adds SMTP email sending abilities to ASP or Perl programs. Features include: attachments, failsafe queueing, redundant servers, standard message file support, and advanced activity logging. Also verify email addresses and send multiple messages on a single connection.
JangoMail, located at JangoMail.com, is a web-based service that sends mass
e-mails by connecting to data from your SQL Server or ODBC compliant
database. Unlike traditional ASP e-mail components, the JangoMail service
can also handle unsubscribes and bounces automatically and synchronize these
with your original web database. The only setup that is required is the
placement of one ASP file on your web server. Other features include
message open tracking and click tracking.
Send Email directly from you web page via your webserver. jMail will not start up any annoying email clients, just smoothly send the mail via the mailserver. Implement it with easy ASP code.
Mail for .NET is the first product for the NetToolworks.NET framework. Together they provide methods that send, receive, compose, edit, encode and decode e-mail messages. SMTP, POP, complex MIME messages, HTML messages, and file/memory streaming are also supported.
A single component that is limited in scope to five methods. The OCXMail ASP component allows you to send mail using the standard SMTP protocol from any program that can use ActiveX/OLE components.
The ocxQmail ASP component allows you to send mail using the standard SMTP protocol from any program that can use ActiveX/OLE components. ocxQmail queues up messages for batch delivery by a companion NT Service at intervals you specify in the Administration Windows GUI.
Your ASP pages do not have to wait for the mail message to be physically sent before continuing.
RobustPOP3 component allows you to retrieve mail using POP3 protocol. Features include: Retrieve Messages
Multiple File Attachments, File Attachments support MIME and UUEncode.
A full-featured SMTP e-mail client component that allows developers to send e-mail from any client. This award-winning control offers significantly better performance than other popular SMTP components. SoftArtisans SMTPmail is written in high-performance C++ and supports all threading models, file attachments and multiple encoding schemes. New features in version 2.0 include login authentication and mass mail. The new version also supports PGP encryption.
Simple mail strictly conforms to the original SMTP standard. It does not support enhanced features like attachments, MIME or multiple character sets. However, it offers high performance, ease of use and a very competitive low price.
Chilkat WebMail is a POP3/SMTP client component packed with
advanced features including: full S/MIME capability, MHTML,
multipart/alternative, multipart/related, attachments, advanced AES encryption, charset conversion, Outlook integration, progress monitoring,
import EML, import/export XML, mail-merge, distribution lists, Chilkat Zip
integration, Outlook contacts and distribution lists, bad email address
detection/collection, SMTP Windows Integrated Authorization, smart cards,
SMTP/POP3 server diagnostics, full control over Cryptographic Service
Providers for S/MIME, auto-handle any charset for any language, and more.
Learn how to run the mail processing component from the first part using Transaction Services provided by COM+ Enterprise Services and see how to use the information available in the SQL Server table to actually send out mail
from a Windows Service. [Read This Article][Top]
Many challenges present themselves when trying to send mail as part of a transaction in an enterprise-class application. Fear not frustrated developer. Thiru Thangarathinam will guide you through the steps of designing an extensible and asynchronous mail processing system. [Read This Article][Top]
Remie Bolte begins his series on developing .NET SMTP and POP3 e-mail components for an outlook express look-alike Web-based e-mail application. This article provides a thorough overview of the SMTP RFC. [Read This Article][Top]
Stop SPAM from sliding through your e-mail system. George Walker shows how to create an e-mail content filter for the Windows 2000 SMTP service using Microsoft Collaboration Data Objects. [Read This Article][Top]
PGP is an encryption program being used for secure transmission of files and e-mails. This article explains the concepts of PGP, provides details about installing and configuring the command-line version of PGP, and explains how an encrypted e-mail can be generated from ASP. [Read This Article][Top]
Dennis Adams explains how accessing Outlook 98 Contacts via a Public Folder from ASP pages is possible if attention is paid to properly installing the necessary components, and configuring the IIS and Exchange Server components. Adams offers some prerequisites, a detailed list of sample code segments, and a complete list of reference materials and related Technet articles. [Read This Article][Top]
Peter Persits' article explains how Secure Multipurpose Internet Mail Extensions, or S/MIME, has come to rescue of e-commerce Web sites that need some order information to be contained in encrypted E-mail. Customers don't want to use automatic on-line credit card authorization, so order information instead is sent over an SSL-protected HTML form and credit card numbers are sent via encrypted E-mail for manual processing. [Read This Article][Top]
In this article Shahriar Moosavizadeh uses a script to report each day's sales data via E-mail to the sales manager. The Windows Scripting Host allows scripts to be executed directly on the desktop and create a report without having to run the script within the HTML document or ASP page. Included is a sample script that both builds the report and E-mails it to the sales manager,
and step-by-step screenshots and instructions.
[Read This Article][Top]
Collaboration Data Object (CDO) is a COM library designed to send mail through SMTP or Microsoft Exchange. If you install the SMTP server that comes with Microsoft Option Pack 4, you can send mail from an Active Server page using CDO. Because CDO is comes with Microsoft Option Pack 4, CDO is free. [Read This Article][Top]
This issue describes how to make a list server using Active Server, SQL Server, and Stephen Genusa's ASPMail Component. Included are source and instructions for adding the user to the list from a Active Server page, removing the user from the list via a Active Server page, and sending mail to the whole list. [Read This Article][Top]
Mailing List
Want to receive email when the next article is published? Just Click Here to sign up.