Problem: getting ???? when send an email in hebrew
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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 );
}
}
// 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 ?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.