Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Send mail with israelian text

Reply
Thread Tools

Send mail with israelian text

 
 
giugy
Guest
Posts: n/a
 
      05-29-2008
Hi, sorry for my english but i don't speak it very well....i have a
problem with my class that send email....

I need to send email with attachments and with subject and body in
israelian (hebrew), and Content-Transfer-Encoding = 8bit...i have some
problem with this....i try to set the message's header with the
charset for hebrew
message.setHeader("Content-Type", "text/plain; charset=ISO-8859-8");
and to set the message's Content-Transfer-Encoding
message.addHeader("Content-Transfer-Encoding", "8bit");

This is my code

import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.*;
import javax.activation.*;

........

Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.password", password);
props.put("mail.smtp.user", userId);

props.put("mail.mime.charset", "ISO-8859-8");
props.put("user.language", "iw");
props.put("sun.jnu.encoding", "ISO-8859-8");
props.put("file.encoding", "ISO-8859-8");

Session session = Session.getDefaultInstance(props, null);

MimeMessage message = new MimeMessage(session);

message.setFrom(new InternetAddress(from));
java.util.StringTokenizer tokenizer = new
java.util.StringTokenizer(to,";");
while (tokenizer.hasMoreTokens()){
message.addRecipient(Message.RecipientType.TO,new
InternetAddress(tokenizer.nextToken()));
}
message.setSubject(subject);

if(copy != null){
java.util.StringTokenizer copyTokenizer = new
java.util.StringTokenizer(copy,";");
while (copyTokenizer.hasMoreTokens()){
message.addRecipient(Message.RecipientType.CC,new
InternetAddress(copyTokenizer.nextToken()));
}
}
// Create the multi-part
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();

messageBodyPart.setText(body);
multipart.addBodyPart(messageBodyPart);
DataSource dataSource;
int index = 0;
if(attaches != null){
for(int i = 0; i < attaches.size(); i++){
messageBodyPart = new MimeBodyPart();
String attach = attaches.get(index).toString();
String attachName = new String();
if(asAttach != null)
attachName = asAttach.get(index).toString();
else
attachName = new java.io.File(attachName).getName();
dataSource = new FileDataSource(attach);
messageBodyPart.setDataHandler(new DataHandler(dataSource));
messageBodyPart.setFileName(attachName);
// Add parts
multipart.addBodyPart(messageBodyPart);
//messageBodyPart = new MimeBodyPart();
++index;
}
}
// Put parts in message
message.setContent(multipart);
message.setHeader("Content-Type", "text/plain;
charset=ISO-8859-8");
message.saveChanges();
message.addHeader("Content-Transfer-Encoding", "8bit");

Transport.send(message);




The problem is that with this code the class doesn't work
fine....infact I receive an email without attachemts, not in hebrew
language and with this body

------=_Part_0_26210109.1212049275627
Content-Type: text/plain; charset=ISO-8859-8
Content-Transfer-Encoding: quoted-printable

BODY TEXT

------=_Part_0_26210109.1212049275627
Content-Type: text/plain; charset=ISO-8859-8; name=debug1.txt
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=debug1.txt

Hello this is attachment test 1
Text present in tha attachment 1

------=_Part_0_26210109.1212049275627
Content-Type: text/plain; charset=us-ascii; name=Z.txt
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=Z.txt

Hello this is attachment test 2
Text present in the attachment 2

------=_Part_0_26210109.1212049275627--


Just for information..from a test that i have done i see that if I use

message.setHeader("Content-Type", "text/xml; charset=ISO-8859-8");

and not

message.setHeader("Content-Type", "text/plain; charset=ISO-8859-8");

the email is incorrect (infact i receive an email without body and
with an .xml as attachments)
but the charset is correct...infact when i try to open the email
Outlook say me that i need to install the support for hebrew (this is
on my Windows machine....i need to use this on a unix machine with
hebrew as default) ..... why with text/plain no, and with text/xml
yes????

How i can do so that this class send me an email with the correct
attachments and with the correct charset for the hebrew????

Thanks for help.bye
 
Reply With Quote
 
 
 
 
GArlington
Guest
Posts: n/a
 
      05-30-2008
On May 29, 11:22 am, giugy <(E-Mail Removed)> wrote:
> Hi, sorry for my english but i don't speak it very well....i have a
> problem with my class that send email....
>
> I need to send email with attachments and with subject and body in
> israelian (hebrew), and Content-Transfer-Encoding = 8bit...i have some
> problem with this....i try to set the message's header with the
> charset for hebrew
> message.setHeader("Content-Type", "text/plain; charset=ISO-8859-8");
> and to set the message's Content-Transfer-Encoding
> message.addHeader("Content-Transfer-Encoding", "8bit");
>
> This is my code
>
> import javax.mail.BodyPart;
> import javax.mail.Message;
> import javax.mail.MessagingException;
> import javax.mail.Multipart;
> import javax.mail.SendFailedException;
> import javax.mail.Session;
> import javax.mail.Transport;
> import javax.mail.internet.*;
> import javax.activation.*;
>
> .......
>
> Properties props = System.getProperties();
> // Setup mail server
> props.put("mail.smtp.host", smtpHost);
> props.put("mail.smtp.password", password);
> props.put("mail.smtp.user", userId);
>
> props.put("mail.mime.charset", "ISO-8859-8");
> props.put("user.language", "iw");
> props.put("sun.jnu.encoding", "ISO-8859-8");
> props.put("file.encoding", "ISO-8859-8");
>
> Session session = Session.getDefaultInstance(props, null);
>
> MimeMessage message = new MimeMessage(session);
>
> message.setFrom(new InternetAddress(from));
> java.util.StringTokenizer tokenizer = new
> java.util.StringTokenizer(to,";");
> while (tokenizer.hasMoreTokens()){
> message.addRecipient(Message.RecipientType.TO,new
> InternetAddress(tokenizer.nextToken()));
> }
> message.setSubject(subject);
>
> if(copy != null){
> java.util.StringTokenizer copyTokenizer = new
> java.util.StringTokenizer(copy,";");
> while (copyTokenizer.hasMoreTokens()){
> message.addRecipient(Message.RecipientType.CC,new
> InternetAddress(copyTokenizer.nextToken()));
> }
> }
> // Create the multi-part
> Multipart multipart = new MimeMultipart();
> BodyPart messageBodyPart = new MimeBodyPart();
>
> messageBodyPart.setText(body);
> multipart.addBodyPart(messageBodyPart);
> DataSource dataSource;
> int index = 0;
> if(attaches != null){
> for(int i = 0; i < attaches.size(); i++){
> messageBodyPart = new MimeBodyPart();
> String attach = attaches.get(index).toString();
> String attachName = new String();
> if(asAttach != null)
> attachName = asAttach.get(index).toString();
> else
> attachName = new java.io.File(attachName).getName();
> dataSource = new FileDataSource(attach);
> messageBodyPart.setDataHandler(new DataHandler(dataSource));
> messageBodyPart.setFileName(attachName);
> // Add parts
> multipart.addBodyPart(messageBodyPart);
> //messageBodyPart = new MimeBodyPart();
> ++index;
> }
> }
> // Put parts in message
> message.setContent(multipart);
> message.setHeader("Content-Type", "text/plain;
> charset=ISO-8859-8");
> message.saveChanges();
> message.addHeader("Content-Transfer-Encoding", "8bit");
>
> Transport.send(message);
>
> The problem is that with this code the class doesn't work
> fine....infact I receive an email without attachemts, not in hebrew
> language and with this body
>
> ------=_Part_0_26210109.1212049275627
> Content-Type: text/plain; charset=ISO-8859-8
> Content-Transfer-Encoding: quoted-printable
>
> BODY TEXT
>
> ------=_Part_0_26210109.1212049275627
> Content-Type: text/plain; charset=ISO-8859-8; name=debug1.txt
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename=debug1.txt
>
> Hello this is attachment test 1
> Text present in tha attachment 1
>
> ------=_Part_0_26210109.1212049275627
> Content-Type: text/plain; charset=us-ascii; name=Z.txt
> Content-Transfer-Encoding: 7bit
> Content-Disposition: attachment; filename=Z.txt
>
> Hello this is attachment test 2
> Text present in the attachment 2
>
> ------=_Part_0_26210109.1212049275627--
>
> Just for information..from a test that i have done i see that if I use
>
> message.setHeader("Content-Type", "text/xml; charset=ISO-8859-8");
>
> and not
>
> message.setHeader("Content-Type", "text/plain; charset=ISO-8859-8");
>
> the email is incorrect (infact i receive an email without body and
> with an .xml as attachments)
> but the charset is correct...infact when i try to open the email
> Outlook say me that i need to install the support for hebrew (this is
> on my Windows machine....i need to use this on a unix machine with
> hebrew as default) ..... why with text/plain no, and with text/xml
> yes????
>
> How i can do so that this class send me an email with the correct
> attachments and with the correct charset for the hebrew????
>
> Thanks for help.bye


Why not try "charset=utf-8"?
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clean way to send HTML e-mail with image using default mail client? Ramon Java 2 10-25-2007 02:02 AM
Syntax for System.Net.Mail send mail Mike P ASP .Net 1 03-01-2007 06:58 PM
Send a mail with System.Net.Mail.SmtpClient refv8 ASP .Net 2 10-13-2006 07:28 PM
Send mail using System.Web.Mail fails w/ m.BodyFormat=MailFormat.H =?Utf-8?B?Unlhbg==?= ASP .Net 2 02-28-2006 01:50 AM
Mail.SmtpMail.Send won't send to one of my addresses Nathan Sokalski ASP .Net 3 11-23-2005 09:25 PM



Advertisments