Java mail encoding

Posted by Argiropoulos Stavros on Stack Overflow See other posts from Stack Overflow or by Argiropoulos Stavros
Published on 2010-03-30T07:53:56Z Indexed on 2010/03/30 8:23 UTC
Read the original article Hit count: 434

Filed under:
|
|

Using the code below i can send an email written in non-english and although the subject appears correctly the body appears as gibberish.
Any ideas?
Thank you

public void postMail(String recipient, String subject, String message, String from) throws MessagingException, UnsupportedEncodingException {

            //Set the host smtp address
            Properties props = new Properties();
            props.put("mail.smtp.host", "mail.infodim.gr");

            // create some properties and get the default Session
            Session session = Session.getDefaultInstance(props, null);

            // create a message
            Message msg = new MimeMessage(session);

            // set the from and to address
            InternetAddress addressFrom = new InternetAddress(from);
            msg.setFrom(addressFrom);

            InternetAddress addressTo=new InternetAddress(recipient);
            msg.setRecipient(Message.RecipientType.TO, addressTo);

            // Setting the Subject and Content Type
            msg.setSubject(subject);

            msg.setContent(message, "text/plain");
            Transport.send(msg);

        }

© Stack Overflow or respective owner

Related posts about java

Related posts about email