Email sending Problem:smtps---SSL---TLS??
843830Jan 12 2007 — edited Jan 14 2007Hi,
I Have a Problem bei Sending a email with Attachement from extranet, I have writting my Programm which will send my email Through TLS, with Thunderbird
I can sending there alle emails through TLS, I have taking the seem Properties :
emai Server Name, Protocol:smtp port:25 und througt TLS, so Now I will show you my Code und the compile Failure, I appreciate so much your Help, I don't find any Help here in Forum.
My Code:
public void sendAttachment(String ausgangsMailServer, String user, String password,String sender, String receiver, String filename) throws MessagingException{
Properties properties = System.getProperties();
properties.put("mail.transport.protocol","smtps");
properties.put("mail.smtps.ssl", "true");
properties.put("mail.smtps.starttls.enable","true");
properties.put("mail.smtps.auth", "true");
properties.put("mail.smtps.debug", "true");
properties.put("mail.smtps.socketFactory.port", "25");
properties.put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtps.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
Session session = Session.getInstance(properties, new MailAuthenticator());
Transport transport = session.getTransport("smtps");
transport.connect(ausgangsMailServer, user, password);
Message message = getMessage(session, sender, receiver,filename);
message.saveChanges();
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
public Message getMessage(Session session, String sender, String receiver, String filename) throws MessagingException{
Message message = new MimeMessage(session);
message.setSubject("attachment");
message.setFrom(new InternetAddress(sender));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(receiver));
Multipart multipart = new MimeMultipart();
BodyPart bp = new MimeBodyPart();
bp.setText("Attachment Mail");
multipart.addBodyPart(bp);
bp = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
bp.setDataHandler(new DataHandler(source));
bp.setFileName(filename);
multipart.addBodyPart(bp);
message.setContent(multipart);
return message;
}
public class MailAuthenticator extends Authenticator{
public MailAuthenticator(){
}
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("radouane","mypaaword");
}
}
And I call the methode sendAttachment in a EJB Methode I Use Jboss als Server in my web application.
This is now my failure:
05:07:21,382 INFO [STDOUT] javax.mail.NoSuchProviderException: smtps
05:07:21,382 INFO [STDOUT] at javax.mail.Session.getService(Session.java:76
4)
05:07:21,382 INFO [STDOUT] at javax.mail.Session.getTransport(Session.java:
689)
05:07:21,382 INFO [STDOUT] at javax.mail.Session.getTransport(Session.java:
632)
05:07:21,382 INFO [STDOUT] at javax.mail.Session.getTransport(Session.java:
612)
---------------------
I have Using a smtps protocol , by using smtp I Had this Failure:
14:15:11,164 INFO [STDOUT] javax.mail.MessagingException: Exception reading res
ponse;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connecti
on?
14:15:11,164 INFO [STDOUT] at com.sun.mail.smtp.SMTPTransport.readServerRes
ponse(SMTPTransport.java:1090)
14:15:11,164 INFO [STDOUT] at com.sun.mail.smtp.SMTPTransport.openServer(SM
TPTransport.java:986)
14:15:11,164 INFO [STDOUT] at com.sun.mail.smtp.SMTPTransport.protocolConne
ct(SMTPTransport.java:197)
14:15:11,164 INFO [STDOUT] at javax.mail.Service.connect(Service.java:233)
14:15:11,164 INFO [STDOUT] at javax.mail.Service.connect(Service.java:134)
For your help I say Thanks.
Radouane