FAQ: Validating Email Addresses before sending

Hi All!
Recently I've been developing a servlet to allow our users to change their email address. The problem with this, of course, is that the user can easily enter an invalid address or simply make an error typing their address. Obviously it's not possible to catch every error, but it is possible to at least verify that the address entered is of a valid format, i.e. [email protected]
The JavaMail API provides some validation in InternetAddress, but again allows some things to slip through the cracks. Here's the code that I've come up with to at least ensure the proper email address format:
import javax.mail.internet.InternetAddress;
import java.net.InetAddress;
public static boolean emailIsValid(String addr)
boolean result=true;
try {
int atPos=addr.indexOf("@");
String host=addr.substring(atPos+1,addr.length());
InternetAddress validAddr = new InternetAddress(addr);
InetAddress inet = InetAddress.getByName(host);
catch (Exception e) {
result=false;
return result;
}The drawback to this solution is that IP address/host name combinations are cached in a static map in the JVM. This means the more hosts that get mapped, the more memory is required by the JVM to cache these hosts in its static Map.
On the other hand, the only time this map should grow is when an email address gets changed, and the address is moved to a previously unknown domain. Hopefully, the memory requirements should not become unbearable during the expected uptime for the JVM.
Hopefully this will help a few people out...!
--David Hibbs

Minor code modification:
try {
inet = java.net.InetAddress.getByName(host);
catch (Exception e) {
inet = java.net.InetAddress.getByName("www." + host);
}This lets domains that don't have an IP entry for their top level but still have a web presence to be considered valid.

Similar Messages

  • Any service available on net to check valid email addresses?jwenting, help.

    Is there any 100% reliable service available on net to check the valid email address so that the mail should not get bounced back if sent to the email id.
    According to jwenting in previous topic, there is one service. Here are his quotes.
    Spammers would love to have such a
    service. Just send random combinations to that
    service at a rate of a hundred thousand a minute and
    you have in a few hours a complete list of all
    working addresses on the net.
    Good enough that you can repeat the process before
    every run and you're never getting bounces again.Could anybody explain what is meant by this?

    He's saying "No there is no such service". It would provide yet another haven for crappy spammers.

  • Campaigns - Hard bounces for valid email addresses

    I am getting hard bounces with 'Bad Mailbox Destination Address' for valid email addresses that everybody internally and externally can email without problem.
    Doesn't instill me with much faith for sending out 10,000 emails next week!

    If you can email that address manually from a regular email address and it goes through fine then it's likely you might be getting blocked by spam filters although usually that would be indicated in your bounce message.
    Is your site fully hosted on BC (ie - with BC's nameservers) or is your domain hosted via an A record to point to BC?  If you are being blocked by spam filters then you are likely using the A record because fully hosted sites on BC have the SPF records in place.
    If you are using an A record to point to BC's servers for your domain and manage your DNS records somwehere then you need to add a TXT record with the SPF data.  Goto your domain registrar and manage your DNS entries.  You'll want to add a TXT record with the following info:
    Record name: @
    Record type: TXT
    Record value: v=spf1 mx include:worldsecuresystems.com ~all
    Record TTL: 86400
    You can only have one SPF record on your domain so if you already have a TXT record with SPF data in it for other email services your domain uses (like gmail) you just need to update your TXT SPF record and add "include:worldsecuresystems.com" after the first "include" statement in the TXT record the TXT value would look like:
    "v=spf1 mx include:_spf.google.com include:worldsecuresystems.com ~all"
    If your problem is that your emails are blocked by spam filters that should fix it but I'm pretty sure 'Bad Mailbox Destination Address' usually indicates a non-existent or malformatted username in your email address (ie - the part before the "@").  I would also double check your subscribers list and make sure there are no spaces or any other invalid character in the email addresses for the customers that are getting bounced back.
    Here's more information about your specific error from http://technet.microsoft.com/en-us/library/bb232118(v=exchg.80).aspx which has to do with MS Exchange server specifically but still provides a good explanation:
    5.1.1
    Bad destination mailbox address
    This failure may be caused by the following conditions:
    The recipient e-mail address was entered incorrectly by the sender.
    No recipient exists in the destination e-mail system.
    The recipient mailbox has been moved and the Microsoft Office Outlook recipient cache on the sender's computer has not updated.
    An invalid legacy domain name (DN) exists for the recipient mailbox Active Directory.
    This error typically occurs when the sender of the message incorrectly enters the e-mail address of the recipient. The sender should check the recipient's e-mail address and send again. This error can also occur if the recipient e-mail address was correct in the past but has changed or has been removed from the destination e-mail system.
    If the sender of the message is in the same Exchange organization as the recipient, and the recipient mailbox still exists, determine whether the recipient mailbox has been relocated to a new e-mail server. If this is the case, Outlook may not have updated the recipient cache correctly. Instruct the sender to remove the recipient address from sender's Outlook recipient cache and then create a new message. Resending the original message will result in the same failure.
    Other issues may cause this error, such as an invalid legacy distinguished name (DN) in Active Directory. Examine and correct the legacy DN of the recipient's mailbox. Then instruct the sender to remove the recipient address from sender's Outlook recipient cache and then create a new message. Resending the original message will result in the same failure.

  • JavaMail and Valid Email Address

    Hello All,
    I am using JavaMail API to send thousands of emails every day through my application running on J2EE application server...
    But what i really want to do is, how do i check whether a particular Email Address is Valid or not,if not valid then catch a exception and report it....
    Also i meant by Valid email address as to be exsisting on that mail server..e.g "[email protected]"...i.e.the user "javamail" should exist on that domain "sun.com"...
    Is there any way which i can do the above thing?
    Also,since i will be sending 1000's of emails every day will it be feasible for me to check each and every email whether it exist or not and then send it.....how much time will it take to do the same...
    Please help me out with this,can anybody give me a Detail desciption and Code of how can i do it...
    Any suggestions are greatly appreciated
    Thanks a million is advance
    Sam

    E-mail generally passes through a whole series of Mail Transfer Agents before arriving on the target machine, and it could be rejected at any stage.
    It may wind up waiting in a queue. It could be days before it reaches a machine that knows whether the user is valid or not.
    And machines aren't as helpful as they used to be about letting out information about available e-mail addresses,
    too many evil spammers about.
    You can test the format, though I've seen a lot of active e-mail addresses with what I believe are invalid characters in them apparently find their way through.
    In theory you could look up the domain part of the address on the DNS. If you don't find either an "A" record or a "MX" record then niether will your mail transfer agent. AFAIK there's no standard java classes for doing that but there may be some out there on the net.
    There's no sure way of validating a user name except sending a mail and see if it bounces.

  • HT1349 how can I change an email for authorization, the email address we used years back, is no longer a valid email address

    how can I change an email for authorization, the email address we used years back, is no longer a valid email address

    SfromW wrote: ... how can I change an email for authorization, the email address we used years back, is no longer a valid email address
    How to change account here: http://support.apple.com/kb/PH1641
    If you need more help, start here: http://www.apple.com/support/itunes/
    SfromW wrote: ... we can't remember the password from the old email address (for authorization)...
    Help Retrieving and changing passwords here: http://support.apple.com/kb/HT1911
    If you need more help, from iTunes for Windows, click  iTunes > iTunes Store > Support
    SfromW wrote: ... apple should make it easier to transfer authorization authority....I would think anyways.
    You might want to rethink your thoughts about making transferring authority easier.  Making it too easy would certainly degrade your account's security.  If you still believe it should be easier, you can send feedback directly to Apple via http://www.apple.com/feedback/itunesapp.html
    You will not get a response, but you can be certain that the responsible Apple people will see your input for consideration in FaceTime product development.
    As a new user, please understand that you are NOT directly addressing Apple here.  For more info about Apple discussions, start here: http://discussions.apple.com/static/apple/tutorial/etiquette.html 
    Message was edited by: EZ Jim
    Mac OSX 10.7.4

  • I restored my ipod touch however the apps will not sync.  I tried to re-download but I changed my apple id as my old id is no longer a valid email address.  Any ideas out there please

    I restored my ipod touch however the apps will not sync.  I tried to re-download but I changed my apple id as my old id is no longer a valid email address.  Any ideas out there please?

    It might be logical to someone, but not to me. I agree it's a pain.
    How did you change your Apple ID? Creating a new one is not what you want to do, but if you changed the ID associated with your purchases then that might have worked. You would need to sign in with the Apple ID on both your iPod Touch as well as in iTunes. I'm not sure how you changed it but clearly they need to match.
    If it's just your password that is not getting recognized reset it here: http://iforgot.apple.com/
    It will send an email confirmation to the email address associated with that Apple ID. The email address you elect to use might not look anything like your Apple ID. If you don't appear to get an email check your spam filter.

  • Event Invite - Select email address to send from

    OK...this is close to my issue, but not the solution I'm looking for:
    discussions.apple.com/message/7009550#7009550
    Not to mention it's three years old....we should've progressed by now.
    So, here's my issue.  Basically I use iCal and Mail for both business and personal applications.  I have a business email address and two personal email addresses associated with my ME card and being used in Mail.  I have a number of calendars set up in iCal, but basically am only interested in dealing with my "Work" and my "Home" calendars.  Is there a way for me to select (or set) which email address I send my invites from depending on which calendar I am using?  i.e.:  if I set up a meeting in my work calendar, I want it to come from my work email.  If I set up a meeting in my Home calendar, I want it to come from one of my personal email addresses.
    The closest solution I have found is setting the "send new mail from" field in Mail Preferences to the appropriate email BEFORE sending the invite.  This does work, but is cumbersome, and not something I would readily remember to do every time.  Not to mention that it is 2011....shouldn't the ability to select my send from email address be a basic function of iCal?

    Thanks. That answers my question, but doesn't help my situation. Not much sense in having alias emails, other then with my MAC/MobileMe, if I can't use them from my iPhone. I have to wait until I return home to reply if I don't want to send from my main email.

  • Spry validation and validating email address?

    I've seen that spry can be used to validate forms. I have not
    seen an
    example of an email address or more complicated validating
    being done.
    Where's a good source for how to do this?

    Validating email addresses is not entirely possible. You can
    only validate
    the SYNTAX of an email address. This is best done server side
    rather than
    client side (or perhaps both ways) since validating only
    client side can be
    defeated by simply disabling javascript.
    I like the Spry validation, though, because it is EXTREMELY
    flexible and
    easy to use. David Powers has some very good discussions
    about Spry in his
    Dreamweaver CS3 with CSS. Ajax, and PHP book, as does David
    McFarland in his
    Dreamweaver CS3: The Missing Manual.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Art" <lee_nospam_@nospam_artjunky.com> wrote in
    message
    news:fe5uke$pu7$[email protected]..
    > I've seen that spry can be used to validate forms. I
    have not seen an
    > example of an email address or more complicated
    validating being done.
    >
    > Where's a good source for how to do this?

  • Hi i use iphone 4 with iso 6.1.3!! Am not getting an option to register my phone number in imsg!! Am just getting an option to set my email address for sending and receiving the imsgs!! How do i register my phone number??

    Hi i use iphone 4 with iso 6.1.3!! Am not getting an option to register my phone number in imsg!! Am just getting an option to set my email address for sending and receiving the imsgs!! How do i register my phone number??

    Hello Nikkii,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    iOS: Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/ts4268
    Troubleshooting telephone-number activation (iPhone only)
    After each step, toggle FaceTime and iMessage off and then on in Settings > Messages and Settings > FaceTime.
    Update to the latest version of iOS.
    Ensure that your iPhone is set to the correct time zone. Tap Settings > General > Date & Time.
    Note: If Set Automatically is on but the incorrect time zone is displayed, turn Set Automatically off and then choose the correct time zone, date, and time. Then turn Set Automatically on again.
    Ensure that FaceTime has not been restricted: Settings > General > Restrictions > FaceTime.
    Verify that you can send SMS messages. You need a valid SMS messaging plan to activate FaceTime.
    Contact your carrier to verify that there are no restrictions or blocks on text messages. Blocks on text messaging will prevent iMessage and FaceTime registration.
    If you are unable to activate iMessage or FaceTime on a device after remote wiping it, wait at least 24 hours and try again.
    If "Waiting for Activation" is displayed, leave FaceTime and iMessage enabled for 24 hours. Toggling FaceTime or iMessage off and on will cause the registration process to start over.
    Best of luck,
    Mario

  • SendFailedException, valid email addresses not sent

    Hi all,
    I'm using the JavaMail 1.2 API to send email to an SMTP server and I'm having a problem with invalid addresses. I'm using the Transport.sendMessage(Message, Address[]) method. The API docs says, ". Also, if any of the addresses is invalid, a SendFailedException is thrown. Note however, that the message is sent to the valid addresses."
    However, if there is an invalid address I get the SendFailedException as expected, but the message is not sent to the valid email addresses.
    Has anyone experienced this? Solutions, workarounds?
    Thanks,
    Derek

    Hello Sir,
    I am working on an Enterprise Java Bean Application running on J2EE application server..Also using JavaMail API to send Emails through my application.
    I am able to send emails successfully through it and sending it into a loop one after the other...
    What i am tring to do is, if i encounter an Invalid Email Address the application throws me an SendFailedException and from this SendFailedException i want to catch Invalid Email Addresses... so that i will come to know which emails where sent and which were not...
    But the problem is that ,if an Invalid Email Address is encountered and after throwing me an SendFailedException if i try to Catch the Invalid Address ,like
    Address[] invalid = sfe.getInvalidAddresses();
    and print an SOP after this,
    System.out.println("Collected InvalidAddress from SendFailedException...."+invalid);
    the SOP prints "Null" ...
    The Invalid Email Address is also an well Formed String....e.g... "[email protected]"...
    The complete Exception is .....
    The exception is javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.SendFailedException: 554 <[email protected]>: Recipient address rejected: Domain not found
    The Code is ..
    <Code>
    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(eMess.getEmailSender()));
    String to = "";
    msg.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse(to, false));
    msg.setRecipients(Message.RecipientType.BCC,
    InternetAddress.parse(eMess.getEmailReceiver(), false));
    msg.setSubject(eMess.getSubject());
    msg.setContent(eMess.getHtmlContents(),"text/plain");
    msg.saveChanges();
    try {
    Transport.send(msg);
    System.out.println ("The Email has been sent successfully....");
    } catch (javax.mail.SendFailedException sfe) {
    System.out.println("The exception in MailHelper is " + sfe);
    ArrayList al = new ArrayList();
    Collection badAddresses = null;
    System.out.println("Collecting InvalidAddress from SendFailedException....");
    Address[] invalid = sfe.getInvalidAddresses();
    System.out.println("Collected InvalidAddress from SendFailedException...."+invalid);//this SOP is Null....
    if (invalid != null) {
    System.out.println("Invalid Addresse(s) found......");
    if (invalid.length > 0) {
    for (int x = 0; x < invalid.length; x++) {
    invalidAddresses = invalid[x].toString();
    System.out.println("The Invalid Addresses are :"+invalidAddresses);
    </Code>
    Can anybody help me out with this problem.Any suggestion or code can be greatly appreciated...
    Thanks a million is advance...
    Regards
    Sam

  • Someone has captured my email address and sending emails saying they are from me.

    Someone has captured my email address and sending messages out to people in my address book making it look like they are  from me. It's for an advertisement on a webpage. How do I get it to stop?
    This has not happened to me in over 3 years when I switched to apple products.
    Anyone that can help me clean this up. Most of the recipients that the link above is being sent to are simply deleting because they know if I was the one asking them to check out the link I would tell them first what it was about before they open it. There is NO message in the email JUST the website.  This is frustrating for me...brings me back 3 years to anti-virus protection with Windows.
    Thank you,
    Bernie
    <Link Edited By Host>

    You may have been infected by a Botnet:
    Simply put, a bot – which is short for robot – is an automated computer program that allows outside sources to control computers remotely without the users' knowledge. A botnet is a network of hundreds or thousands of computers infected with botnet malware that communicates covertly with a command-and-control (CnC) server run by a type of cybercriminal called a botmaster. Unbeknownst to the individual users, their computers are linked in a rogue network which the botmaster can utilize for a variety of nefarious purposes.
    Detailed information here:
    http://mac-internet-security-software-review.toptenreviews.com/how-do-i-know-if- my-computer-is-a-botnet-zombie-.html

  • Does anyone have an email address to send a security issue to apple?

    found something they should know about (if they don't already) and wonder how to tell them... tried calling... no real email's listed... it's not a bug that hasn't already hit them in the past but still don't wanna post it on the boards.
    so my question is: anyone know a valid email address that i can send a security issue about the iphone to?

    http://www.apple.com/support/security/

  • Why can't I cut and paste email addresses when sending documents?

    Why can't I cut and paste email addresses when sending files? I have to type them in each time...And it doesn't remember them for the future, as SendNow did.
    Also, it seems that the message I type in is not kept, as it was with SendNow?
    Thanks!

    Hi drlaura,
    You're correct on both counts--these features work differently Adobe Send than they do in Adobe SendNow.
    If you're sending files from Adobe Reader, you can access your local Address Book, which should make entering email addresses easier. Please see: I’m trying to send a file from Adobe Reader, but I can’t access my computer’s address book to find my contacts. Why not?
    Please let us know how it goes.
    Best,
    Sara

  • I can't set up my email account on my ipod touch.  It keeps saying that I have to use a valid email address for this account

    I can't set up my email on my ipod touch.  It keeps saying I have to use a valid email address for this account.  Help!

    Hi Annie,
    Make sure when you are setting up your e-mail account that you enter in your entire e-mail address.  If you have a Yahoo (includes any e-mail account associated with Yahoo), G-mail, or Aol after entering in your password it should automatically set up.  Any other e-mail address you will have to manually set the account up.

  • "" does not appear to be a valid email address. Verify the address and try again.

    I am getting this error whenever I copy an email address from somewhere and paste it into the 'To' field.
    “” does not appear to be a valid email address. Verify the address and try again.
    Whattup with that?
    Only way to get around it seems to be either typing the whole address in (uh!) or clicking on the email address and letting Mail create the new message. Both are not the way I need to do things and it used to work perfectly in Snow Leopard, as would be expected for such a basic sort of command.

    I had the same problem with multiple adressess:
    I used the " ; "  as a seperator.
    The message was sent with no trouble at all as soon as I used the " , " (comma) instead.
    Hope this helps

Maybe you are looking for

  • Does the iPod nano come with a means to charge the battery?

    Does the iPod nano come with a means to charge the battery?

  • Sepia color though the whole catalog (LR 3.6)

    All of my photos now have a sepia tone where they used to show white. In the develop module the white in the histogram is also now sepia. I have tried restoring a backup and it has the same problem for all 15000 photos. Any ideas on how I can fix thi

  • RFC_CALL_TRANSACTION missing

    Hello, we had used to remote call  the transaction RFC_CALL_TRANSACTION 9SAP R/3 4.4C). Aftre upgrade to ECC 6.0 the transaction RFC_CALL_TRANSACTION does not exist. Which one can we use instead of it? Regards Zeno Edited by: zeno novak on Jun 18, 20

  • IPhoto and Finder

    I am beginning to understand that you should only work within iPhoto for adding, deleting, copying, amending names etc of photos. What then is the purpose of the files in Documents / My Pictures (viewed in Finder)? If it doesn't contain all the photo

  • Problems with mouse buttons after update

    In recent days, for no apparent reason, I am experiencing problems with the mouse. The right button is set to right-click does not work and the role of the side buttons have also changed. A friend who also has a similar iMac is experienced problems f