Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java mail  RSS feed

 
Manuel Paco
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 = "manuelpaco@netzero.net";
String to = "manuelpaco@yahoo.com, manuelpaco@netzero.net";
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 = "paco@netzero.net";
String password = "manuel";
transport.connect( smtpHost, user, password );

transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
transport.close();
}
}//end SendEmail
 
Ulas Ergin
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make sure your classpath contains mail.jar and activation.jar
 
Manuel Paco
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Path is OK. Still does not work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!