Send mail with israelian text

Discussion in 'Java' started by giugy, May 29, 2008.

  1. giugy

    giugy Guest

    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
     
    giugy, May 29, 2008
    #1
    1. Advertising

  2. giugy

    GArlington Guest

    On May 29, 11:22 am, giugy <> 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"?
     
    GArlington, May 30, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    3
    Views:
    1,953
    Larry Lard
    Nov 23, 2005
  2. =?Utf-8?B?Unlhbg==?=
    Replies:
    2
    Views:
    3,913
    Steven Cheng[MSFT]
    Feb 28, 2006
  3. refv8
    Replies:
    2
    Views:
    27,094
    ittower
    Oct 13, 2006
  4. Mike P
    Replies:
    1
    Views:
    572
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 1, 2007
  5. Ramon
    Replies:
    2
    Views:
    1,023
    Ramon
    Oct 25, 2007
Loading...

Share This Page