Help please.
When I run the following code I get
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/plain
code
public class SendEmail
{
protected void sendEmailMethod() throws IOException
{
String from = "
[email protected]";
String to = "
[email protected],
[email protected]";
String subject = "JAVASendMailexample";
String message = "Mymessage";
try{
MailSending( from, to, subject, message );
}
catch(UnknownHostException uhe){System.out.println(uhe);}
catch(MessagingException me){System.out.println(me);}
}
public void MailSending(String from, String to, String subject, String message) throws MessagingException, IOException
{
String smtpHost="smtp.netzero.net";
// Get system properties
Properties properties=System.getProperties();
// Setup mail server
properties.put("mail.smtp.host", smtpHost);
// Get session
Session session=Session.getInstance(properties,null);
MimeMessage mimeMessage=new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress(from));
InternetAddress[] tos = InternetAddress.parse((String)(to));
mimeMessage.setRecipients(Message.RecipientType.TO,tos);
mimeMessage.setSubject(subject);
mimeMessage.setContent(message, "text/plain");
Transport transport=session.getTransport("smtp");
String user = "
[email protected]";
String password = "manuel";
transport.connect( smtpHost, user, password );
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
transport.close();
}
}//end SendEmail