LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-29-2006, 01:24 PM   #1
yace
LQ Newbie
 
Registered: Jan 2006
Posts: 4

Rep: Reputation: 0
Problem: getting ???? when send an email in hebrew


Hi Guys,

I have a site that developed by java, jsp's on linux server (fedora core 4)
In my site there is an option to send e-mails ("contact me" ) to my e-mail box.
In every time that I'm sending / getting an email in Hebrew language from site - I'm getting
???????

The charset in my jsp's are correct.
If I'm loading the site on windows XP (localhost) - getting the e-mail in Hebrew.

Please help ?

Thanks,

Yace.
 
Old 01-29-2006, 07:44 PM   #2
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
we can't really know exactly how the mail is being transmitted with what you said.
java has a way to send mail as diffeent encodings as part of the Sun Java extension package JavaMail and
JavaBeanActivationFrameWork
i will look up the code if you need how to do it cause i did it once but will have to look for the code.

when you say it displays ??? it sounds a like whatever you are using to read the mail is not configured correctly.

you say you get the mail correctly using windows ?
are you using UTF-8 and did you set your Linux browser to UTF-8 or whatever charset you are using ?

Last edited by foo_bar_foo; 01-29-2006 at 07:48 PM.
 
Old 01-30-2006, 02:27 AM   #3
yace
LQ Newbie
 
Registered: Jan 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Hi foo_bar_foo,
thanks alot for your replay.
I'm using IE browser to insert the text msg,
Then using Outlook express to read the mail.

The Flow:
1. Insert text (by IE browser), Press on submit.
================================================
2. In the Jsp:
==============
request.setCharacterEncoding("UTF8");
String YOUR_NAME = "";
String YOUR_EMAIL = "myEmail";
String RECIPIENT_NAME = "";
String RECIPIENT_EMAIL = "something";
String EMAIL_SUBJECT = "contact me";
String EMAIL_TEXT = request.getParameter("text");
String SMTP_HOST = "SMTP_HOST";
int SMTP_PORT = 25;

email.Message msg = new email.Message();
email.Transport tr = new email.Transport( SMTP_HOST, SMTP_PORT );
msg.setFrom( new email.Address( YOUR_NAME, YOUR_EMAIL ) );
msg.setRecipient( email.RecipientType.TO, new email.Address( RECIPIENT_NAME, RECIPIENT_EMAIL ) );
msg.setSubject( EMAIL_SUBJECT );
msg.setText( EMAIL_TEXT );

try {
tr.send( msg );
....

3. In Java:
===========
public void send( Message msg ) throws TransportException {
PrintWriter out = null;
BufferedReader in = null;

try {
Socket s = new Socket( this.smtpHost, this.smtpPort );
out = new PrintWriter( s.getOutputStream(), true );
in = new BufferedReader( new InputStreamReader( s.getInputStream() ) );

sendMessage( msg, in, out );
}
private void sendMessage( Message msg, BufferedReader in, PrintWriter out ) throws TransportException {

Address[] from = msg.getFrom();

Address[] to = msg.getRecipients( RecipientType.TO );
for( int i=0; i<to.length; i++ ) {
out.println( "RCPT TO: <"+ to[i].getAddress() +">" );

Address[] cc = msg.getRecipients( RecipientType.CC );
for( int i=0; i<cc.length; i++ ) {
out.println( "RCPT TO: <"+ cc[i].getAddress() +">" );
if( smtpErrorExists( in,"250" ) ) {
throw new TransportException( "SMTP error: adding a CC recipient failed. Error with this address: " + cc[i].getAddress() + "\t" + smtpResponse );
}
}
Address[] bcc = msg.getRecipients( RecipientType.BCC );
for( int i=0; i<bcc.length; i++ ) {
out.println( "RCPT TO: <"+ bcc[i].getAddress() +">" );
if( smtpErrorExists( in,"250" ) ) {
throw new TransportException( "SMTP error: adding a BCC recipient failed. Error with this address: " + bcc[i].getAddress() + "\t" + smtpResponse );
}
}

// From:
if( from != null ) {
out.println( "From: "+ ( (from[0].getPersonal() != null) ? from[0].getPersonal()+" " : "" ) + "<"+ from[0].getAddress() +">" );
}
// To:
if( to != null && to.length > 0 ) {
StringBuffer buf = new StringBuffer();
buf.append( "To: " );
for( int i=0; i<to.length; i++ ) {
buf.append( (to[i].getPersonal()!=null)
? ( to[i].getPersonal() + " <" + to[i].getAddress() + ">" )
: ( to[i].getAddress() ) );
if( i < to.length-1 ) { // add commas between emails
buf.append( ", " );
}
}
out.println( buf.toString() );

// CC:
if( cc != null && cc.length > 0 ) {
StringBuffer buf = new StringBuffer();
buf.append( "CC: " );
for( int i=0; i<cc.length; i++ ) {
buf.append( (cc[i].getPersonal()!=null)
? ( cc[i].getPersonal() + " <" + cc[i].getAddress() + ">" )
: ( cc[i].getAddress() ) );
if( i < cc.length-1 ) // add commas between emails
buf.append( ", " );
}
out.println( buf.toString() );
}
// Reply-To: (there should only be one reply-to address)
Address replyTo = msg.getReplyTo();
if( replyTo != null ) {
String rt = replyTo.getAddress();
if( rt != null && rt.length() > 0 ) {
StringBuffer buf = new StringBuffer();
buf.append( "Reply-To: " );
buf.append( (replyTo.getPersonal()!=null)
? ( replyTo.getPersonal() + " <" + replyTo.getAddress() + ">" )
: ( replyTo.getAddress() ) );
out.println( buf.toString() );
}
}
// Subject:
if( msg.getSubject() != null ) {
out.println( "Subject: "+ msg.getSubject() );
}
// Email body:
if( msg.getText() != null ) {
out.println( msg.getText() );
}
// End:
// Signal that we're done with the email by printing the DATA section with
// a dot on a line by itself.
out.println( "." );

// Check to see if the message was successfully queued for delievery:
if( smtpErrorExists( in,"250" ) ) {
throw new TransportException( "Error: Message failed to be sent.\t" + smtpResponse );
}

// Exit the SMTP port
out.println( "QUIT" );
} // else

out.close();

}

4. Mybe I have a problem with the charsets in the linux OS ?

If read the mail is not configured correctly why in windows xp i saw the hebrew correctly ?

Thanks.
 
Old 01-31-2006, 11:39 AM   #4
yace
LQ Newbie
 
Registered: Jan 2006
Posts: 4

Original Poster
Rep: Reputation: 0
any news guys ???
 
Old 01-31-2006, 03:35 PM   #5
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
this works for encoding in java using
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
http://www.javacommerce.com/displayp...l.sql&id=18274
and look at my code
sorry don't know about jsp
my encodings are just stored in a static variable of class JEditPad
what you want is "UTF8" but you can use any encoding java supports
client needs JavaMail
Code:
try {
	    Properties props = System.getProperties();
	    props.put("mail.smtp.host", host);
	    Session session = Session.getDefaultInstance(props, null);
	    session.setDebug(true);

	    Message msg = new MimeMessage(session);
	    msg.setFrom(new InternetAddress(from));
	    InternetAddress[] address = {new InternetAddress(replyTo)};
	    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
	    ((MimeMessage)msg).setSubject(subjectSend, JEditPad.encoding);
	    msg.setSentDate(new Date());
	    ((MimeMessage)msg).setText(body, JEditPad.encoding);
	    msg.setHeader("X-Mailer", "JEditPad");
	    Transport.send(msg);
	    System.out.println("\nMail was sent successfully.");
	    int res = JOptionPane.showConfirmDialog(null, "Mail was sent successfully.","JEditPad",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE );

	}
	catch (Exception e) {
	    e.printStackTrace();
	    int ress = JOptionPane.showConfirmDialog(null, "Mail was not sent successfully \n there was an error","JEditPad",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE );
	}
    }

Last edited by foo_bar_foo; 01-31-2006 at 03:39 PM.
 
Old 02-02-2006, 09:24 AM   #6
yace
LQ Newbie
 
Registered: Jan 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Hi foo_bar_foo,
You are right, The code that I used before is not include Encoding.
I added the encoding and it's working good.
Thanks alot alot ...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
email 'send' NO - email 'receive' YES..? captain skywave Linux - Wireless Networking 4 04-23-2005 03:35 AM
email 'send' YES - email 'receive' NO..? captain skywave Linux - Wireless Networking 1 04-22-2005 05:23 AM
problem to send email... os2 Linux - Software 1 09-10-2004 03:15 PM
slack store email problem. cant send to them. xushi Slackware 4 04-14-2004 02:25 PM
Allowing an IP to send email using my email server... culprit Linux - Networking 7 09-09-2003 12:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration