Hello everyone
I need some serious help.
I'm trying to send a mail with UTF-8 content and a file attachment; i have the folloiwng lines of code to do that:
MimeBodyPart mbpContent = new MimeBodyPart();
mbpContent.setText( content, "text/plain; charset=UTF-8" );
Multipart multiPart = new MimeMultipart();
multiPart.addBodyPart( mbpContent );
for ( int i = 0; i < files.length; i++ )
{
MimeBodyPart mbpFile = new MimeBodyPart();
FileDataSource fileDataSource = new FileDataSource( files[i] );
mbpFile.setDataHandler( new DataHandler( fileDataSource ) );
mbpFile.setFileName( fileDataSource.getName() );
multiPart.addBodyPart( mbpFile );
}
msg.setContent( multiPart );
((MimeMessage)msg).setSubject( subject);
Transport.send( msg );
The code works fine if i use:
mbpContent.setText( content );
instead of,
mbpContent.setText( content, "text/plain; charset=UTF-8" );
When i add the
.setText( content, "text/plain; charset=UTF-8" );
part, it throws an exception.
javax.mail.MessagingException thrown when trying to send mail: Sending failed;
nested exception is:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.UnsupportedEncodingException: text/plain; charset=UTF-8; nested exception (class javax.mail.SendFailedException) - Sending failed;
nested exception is:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.UnsupportedEncodingException: text/plain; charset=UTF-8
at mtrack.cda.utils.CDAUtils.mailCommunication(CDAUtils.java:1327)
at mtrack.cda.sejb.CommunicationManagerBean.issueCommunication(CommunicationManagerBean.java:864)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at allaire.ejipt._BeanMethod._invoke(allaire/ejipt/_BeanMethod.java:166)
at allaire.ejipt._SessionObject._invoke(allaire/ejipt/_SessionObject.java:182)
at allaire.ejipt._CallableObject.call(allaire/ejipt/_CallableObject.java:101)
at allaire.ejipt._CallableStub._call(allaire/ejipt/_CallableStub.java:199)
at mtrack.cda.sejb.CommunicationManagerObject_Stub.issueCommunication(CommunicationManagerObject_Stub.java:304)
at mtrack.cda.servlets.IssueCommunication.handler(IssueCommunication.java:243)
at mtrack.cda.servlets.IssueCommunication.doPost(IssueCommunication.java:81)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1552)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1542)
at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:364)
at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:115)
at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)
How can i go around this, and how can i make sure the mail is sent as UTF-8. Any ideas - please let me know.
Many thanks - in anticipation
Pratim