简体   繁体   中英

Java Mail is sending to Wrong Address

When I am trying to send an email to pperson@gmail.com it ends up being sent to p.person@gmail.com


Send Email Code:

  String to = "pperson@gmail.com"; String from = "web@gmail.com"; String host = "localhost"; Properties properties = System.getProperties(); properties.setProperty("mail.smtp.host", host); Session session = Session.getDefaultInstance(properties); try{ MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("This is the Subject Line!"); message.setText("This is actual message"); Transport.send(message); System.out.println("Sent message successfully...."); }catch (MessagingException mex) { mex.printStackTrace(); } 

It works correctly with other emails, why doesn't this one work?

Google Mail API suggests and states that:

Gmail doesn't recognize dots as characters within usernames, you can add or remove the dots from a Gmail address without changing the actual destination address; they'll all go to your inbox, and only yours.

For example:

  • homerjsimpson@gmail.com = hom.er.j.sim.ps.on@gmail.com
  • homerjsimpson@gmail.com = HOMERJSIMPSON@gmail.com
  • homerjsimpson@gmail.com = Homer.J.Simpson@gmail.com

All these addresses belong to the same person. You can see this if you try to sign in with your username, but adding or removing a dot from it. You'll still go to your account.


Google Apps does recognize dots. If you'd like to have a dot in your username, please ask your domain administrator to add your preferred username as a nickname.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM