Solved

JavaMail message - removing 2 last characters

Posted on 2004-09-13
29
205 Views
Last Modified: 2013-11-24
Hi!
Have you encountered the problem that the last 2 characters were removed from your message?
I'm using javamail 1.3
Thanks
0
Comment
Question by:rzvika2
  • 11
  • 8
  • 4
  • +2
29 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12045054
No.  Can you post your code?
0
 

Author Comment

by:rzvika2
ID: 12045206
I'ts a regular and simple code, not something special,
actually, when I send it to one address the text is ok, but when I send it to another, it remove the last two chars.
If I send to the problematic email address a mail from yahoo, for example, it gets the message in the right way.
The code is something similar to this:

          Message msg = new MimeMessage(session);
          msg.setFrom(new InternetAddress(from));
          InternetAddress[] address = {new InternetAddress(args[0])};
          msg.setRecipients(Message.RecipientType.TO, address);
          msg.setSubject("JavaMail APIs Test");
          msg.setSentDate(new Date());
          // If the desired charset is known, you can use
          // setText(text, charset)
          msg.setText(msgText);
          
          Transport.send(msg);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12045254
What *are* the last two characters? They may be chars not supported by the default charset
0
 

Author Comment

by:rzvika2
ID: 12045282
they are regular chars (in my last test, it was 'xt')
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12045289
Is it always the same address that it fails on?

>          msg.setText(msgText);

what is "msgText"?

Tim
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12045321
Perhaps add two extra characters to the string :P lol
[r.D]
0
 

Author Comment

by:rzvika2
ID: 12045325
Yes, it is always the same address(es) (the same domain)
The message text is:
Text line1
Text line2

but what I get in the second line is
Text lin
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12045329
Are you sure it's not some 'budget' provider truncating your message out of 'economy'?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12045342
Substitute a different String and see if it gets truncated at the same offset ;-)
0
 

Author Comment

by:rzvika2
ID: 12045350
Yes, DrWarezz, I've thought of that, but try all the ways before work arounds... ;-)
0
 

Author Comment

by:rzvika2
ID: 12045361
yes, always truncated by two chars, as I've specified in the question...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12045369
>>yes, always truncated by two chars, as I've specified in the question...

In that case, i'll stick to my guess above as to why ;-)
0
 

Author Comment

by:rzvika2
ID: 12045386
CEHJ, when I send this email from another mail acount (and not from my javacode) it works fine.
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12045411
Have you tried using another SMTP server?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 86

Expert Comment

by:CEHJ
ID: 12045448
>>CEHJ, when I send this email from another mail acount (and not from my javacode) it works fine.

Hmm. That's weird. How are you setting 'msgText' and what's in it?
0
 

Author Comment

by:rzvika2
ID: 12045467
no, but again, if I send the same message to 2 different emails, and only in one of them I get the message truncated, why should it be the server problem?
0
 

Author Comment

by:rzvika2
ID: 12045476
setText("Text - line1\nText - line2");
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12045508
You've got me stumped ;-) Try telnetting in and see what happens when you do it manually
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12045585
Isn't there some standard where mails must end with a CR/LF?

Like when you telnet into port 25, the last line has to end with a CR/LF

Sounds to me like the mail server that fails is being a bit heavy handed with its treatment of the specification...

So as a solution, do as DrWarezz says, and just append "\n\r" to the end of any email you send...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12045607
>>Isn't there some standard where mails must end with a CR/LF?

No, they must end with a dot on a line on its own. This probably has nothing to do with the problem though ;-)
0
 

Author Comment

by:rzvika2
ID: 12045639
Actually, when I append two spaces, it's ok.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12047289
> No, they must end with a dot on a line on its own. This probably has nothing to do with the problem though ;-)

Yeah, but the line of text before it would have \n\r on it ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12047339
Yes. Are we any nearer to explaining this mystery?
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12047547
Let's just blame someone, and close it :P lol
0
 

Author Comment

by:rzvika2
ID: 12047597
LOL
Just don't blame me ;-)
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12047638
lol - Who else? :P

Anyways, let's be serious now: I would put it down to being a stupid server problem.. Have you found that appending those two spaces fixes it? If so, then that's probably as close to fixing it as you're going to get  lol (atleast in my eyes).

Best of luck,
[r.D]
0
 

Author Comment

by:rzvika2
ID: 12047681
Yes, appending two spaces solves it.
Thank you all for such a good spirit!
Have fun!
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12319471
PAQed, with points refunded (100)

Computer101
E-E Admin
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 123
Java asynchronous logging 4 50
Way to decrease size of apk file 9 40
MySQL  on Tomcat 8 23
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now