473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to setup option to check if email is valid before sending?

489 256MB
Currently I have an email option that allows users to send out mass emails, they can select certain groups or send to the complete database that has an email address. The option uses MS Outlook, everything works great, but Outlook has a funny problem that if the email address isn't complete like missing the .com etc then Outlook will not send out anything and gives no message as to what email is wrong. I would like to put a check in this e-mail option that would check ahead of time and make sure the email is complete. I know this option should have been in the input screen where that information was entered but didn't know how and at the time didn't have this email option in the program.
Hopefully someone will have some code that will check for a complete e-mail address.
Thanks again for all your help
Feb 7 '11 #1

✓ answered by TheSmileyCoder

I dont know if there are any official "rules" for emails, but this is something I threw together for you:

Expand|Select|Wrap|Line Numbers
  1. Public Function fBoolValidEmail(strEmail As String) As Boolean
  2. 'Purpose: To make a few basic checks on email addresses to determine if they are valid
  3. 'Author:  TheSmileyCoder
  4.  
  5.  
  6. 'Check that we received something
  7.     If strEmail & "" = "" Then
  8.         fBoolValidEmail = False
  9.         Exit Function
  10.     End If
  11.  
  12. 'Checks that there is a @ in string
  13.     Dim intAT As Integer
  14.     intAT = InStr(1, strEmail, "@")
  15.     If Not intAT > 0 Then
  16.         fBoolValidEmail = False
  17.         Exit Function
  18.     End If
  19.  
  20. 'Check that there is a . on the right hand side of the @
  21.     Dim intDOT As Integer
  22.     intDOT = InStr(intAT, strEmail, ".")
  23.     If Not intDOT > intAT Then
  24.         fBoolValidEmail = False
  25.         Exit Function
  26.     End If
  27.  
  28. 'Check that the . part is either .com or .dk or .org
  29.     Dim strDomain As String
  30.     strDomain = LCase(Right(strEmail, Len(strEmail) - InStrRev(strEmail, ".")))
  31.     Select Case strDomain
  32.         Case "dk", "com", "org"
  33.             'Valid
  34.                 fBoolValidEmail = True
  35.                 Exit Function
  36.         Case Else
  37.             'POSSIBLY invalid
  38.                 fBoolValidEmail = False
  39.             'If you want, you can comment out the following line
  40.                 MsgBox "Unknown domain found:" & strDomain
  41.             Exit Function
  42.  
  43.     End Select
  44. End Function
I think that should atleast satisfy outlook. If you want to confirm the emails are valid, you can take a look at a something like this:
Validating Emails

2 2297
TheSmileyCoder
2,322 Expert Mod 2GB
I dont know if there are any official "rules" for emails, but this is something I threw together for you:

Expand|Select|Wrap|Line Numbers
  1. Public Function fBoolValidEmail(strEmail As String) As Boolean
  2. 'Purpose: To make a few basic checks on email addresses to determine if they are valid
  3. 'Author:  TheSmileyCoder
  4.  
  5.  
  6. 'Check that we received something
  7.     If strEmail & "" = "" Then
  8.         fBoolValidEmail = False
  9.         Exit Function
  10.     End If
  11.  
  12. 'Checks that there is a @ in string
  13.     Dim intAT As Integer
  14.     intAT = InStr(1, strEmail, "@")
  15.     If Not intAT > 0 Then
  16.         fBoolValidEmail = False
  17.         Exit Function
  18.     End If
  19.  
  20. 'Check that there is a . on the right hand side of the @
  21.     Dim intDOT As Integer
  22.     intDOT = InStr(intAT, strEmail, ".")
  23.     If Not intDOT > intAT Then
  24.         fBoolValidEmail = False
  25.         Exit Function
  26.     End If
  27.  
  28. 'Check that the . part is either .com or .dk or .org
  29.     Dim strDomain As String
  30.     strDomain = LCase(Right(strEmail, Len(strEmail) - InStrRev(strEmail, ".")))
  31.     Select Case strDomain
  32.         Case "dk", "com", "org"
  33.             'Valid
  34.                 fBoolValidEmail = True
  35.                 Exit Function
  36.         Case Else
  37.             'POSSIBLY invalid
  38.                 fBoolValidEmail = False
  39.             'If you want, you can comment out the following line
  40.                 MsgBox "Unknown domain found:" & strDomain
  41.             Exit Function
  42.  
  43.     End Select
  44. End Function
I think that should atleast satisfy outlook. If you want to confirm the emails are valid, you can take a look at a something like this:
Validating Emails
Feb 7 '11 #2
CD Tom
489 256MB
That looks like it might do it. I'll give it a try in a little while and let you know how it works. Thanks for all your help.
Feb 7 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: dixie | last post by:
I have some code that adds new records into a table for each ID in a list box when a button on a form is clicked. This works fine. My problem now is that I wish to be able to edit all the records...
2
by: Sky | last post by:
Hello: Another question about trying to wring functionality from a DataGrid... Have a DB table of "Contacts" -- 14 or more fields per record Show in datagrid -- but only 5 columns (First,Last,...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
3
by: Schultz | last post by:
is there an easy to follow, source code in one document, article that explains how to create an edit all DataGrid control? and, I have a DataGrid setup where the client enters information for...
8
by: =?Utf-8?B?bWlrZWc=?= | last post by:
Hi, I am building a small Help Desk application for my company and need to be able to edit "open" help desk issues. I use a simple datagrid to display each issue (6 per page) , with an Edit...
1
by: ollielaroo | last post by:
Hi guys, Firstly I did do a search for this one first but I couldn't find anything related in this forum. I am using Dreamweaver MX and trying to build admin pages for an ASP site. My problem is...
1
by: Anette | last post by:
I found the FAQ: I can't find any "edit" button by my post. The FAQ says "Your ability to edit your posts may also be time-limited, depending on how the administrator has set up the forum." I...
5
by: Ryan Liu | last post by:
I have this problem: "cannot continue edit while debug in VS2005". I see the same tread after I search this topic in google, but none solutions works for me. So again, I ask here. Can someone...
1
by: rogerford | last post by:
I have a grid which i bind with values from Database. I have events to edit and update the grid. I am not using SqlDatasource to connect to DB. Rather i am doing the updating of the grid...
1
by: chromis | last post by:
Hi, I'm having trouble fully implementing the edit section of a contact admin system, so far I have written the following: - Bean (Contact.cfc) - Data Access object (ContactDAO.cfc) - Gateway...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.