Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Email character issue  RSS feed

 
Ed Carrington
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to figure out how to escape the & character in my JSP and Java files.

Mailto link not working because it cuts off the mail string after Data:


Java email in Java class:




I also tried double escape slashes and it still not working.
Please advise how I escape or handle the & character.
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ed,

Since the email address is a part of href of the A tag, you should use URL encoder to encode it. For the email address "Data&Location\@mycompany.com", the actual value should be Data%26Location@mycompany.com



Hope it helps,

Duc
 
Ed Carrington
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that worked for my JSP.

The Java class for my email program still is not working.

None of the emails got sent because of the & issue with the first array value.
The email program does work if I eliminate the email with the &.

Here are my attempts:


 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ed Carrington wrote:
None of the emails got sent because of the & issue with the first array value.
The email program does work if I eliminate the email with the &.

Here are my attempts:



Can you elaborate this? My previous solution is only used in href of A tag. It has nothing to do with sending an email in Java.
 
Ed Carrington
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using JavaMail to send the emails out and it always worked in the past.
The & is the issue that is causing it to now work now. How do I handle that character in my String array using JavaMail?
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaMail should have no problem with "&" character, which is a valid character of an email address.

What is your code? (i.e. how did you set the recipients to the message?)
what was the error? (i.e. exception occur somewhere or some recipients received emails, some didn't?)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!