Email sending Problem:smtpsSSLTLS?

Hi,

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

[4080 byte] By [radouane.marjania] at [2007-11-26 14:57:12]
# 1
JBoss probably comes with an older version of JavaMailbundled with it. The older version doesn't know aboutthe "smtps" protocol. Even if you're including a newerversion with your application, it's probably using the olderversion bundled with JBoss.
bshannona at 2007-7-8 8:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi,

Thanks bshannon for your answer.

The Program works successful but like a simple java application, now I want to bind my Programm in my web application so I must deploy the Javamail Program in JBOSS. Here was no Problem, but by sending a email, I Have

The following Failure. I think I must do some settings in my Jboss. Have sssomeone an idea or a link.

I apreciate your Helps.

Radouane

-

2007-01-13 01:41:07,606 INFO [STDOUT] DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]

2007-01-13 01:41:07,606 INFO [STDOUT] DEBUG SMTP: useEhlo true, useAuth true

2007-01-13 01:41:07,606 INFO [STDOUT] DEBUG SMTP: useEhlo true, useAuth true

2007-01-13 01:41:07,606 INFO [STDOUT] DEBUG SMTP: trying to connect to host "mail.cs.tu-berlin.de", port 25

2007-01-13 01:41:07,746 INFO [STDOUT] 220 mailhost.cs.tu-berlin.de ESMTP Postfix

2007-01-13 01:41:07,746 INFO [STDOUT] DEBUG SMTP: connected to host "mail.cs.tu-berlin.de", port: 25

2007-01-13 01:41:07,746 INFO [STDOUT] EHLO meknes

2007-01-13 01:41:07,806 INFO [STDOUT] 250-mailhost.cs.tu-berlin.de

250-PIPELINING

250-SIZE

250-VRFY

250-ETRN

250-STARTTLS

250-ENHANCEDSTATUSCODES

250 8BITMIME

2007-01-13 01:41:07,806 INFO [STDOUT] DEBUG SMTP: Found extension "PIPELINING", arg ""

2007-01-13 01:41:07,806 INFO [STDOUT] DEBUG SMTP: Found extension "SIZE", arg ""

2007-01-13 01:41:07,806 INFO [STDOUT] DEBUG SMTP: Found extension "VRFY", arg ""

2007-01-13 01:41:07,806 INFO [STDOUT] DEBUG SMTP: Found extension "ETRN", arg ""

2007-01-13 01:41:07,806 INFO [STDOUT] DEBUG SMTP: Found extension "STARTTLS", arg ""

2007-01-13 01:41:07,806 INFO [STDOUT] DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""

2007-01-13 01:41:07,806 INFO [STDOUT] DEBUG SMTP: Found extension "8BITMIME", arg ""

2007-01-13 01:41:07,806 INFO [STDOUT] DEBUG SMTP: use8bit false

2007-01-13 01:41:07,806 INFO [STDOUT] MAIL FROM:<radouane@cs.tu-berlin.de>

2007-01-13 01:41:07,876 INFO [STDOUT] 250 2.1.0 Ok

2007-01-13 01:41:07,876 INFO [STDOUT] RCPT TO:<estel1212@yahoo.fr>

2007-01-13 01:41:07,946 INFO [STDOUT] 554 5.7.1 <estel1212@yahoo.fr>: Recipient address rejected: Access denied

2007-01-13 01:41:07,956 INFO [STDOUT] DEBUG SMTP: Invalid Addresses

2007-01-13 01:41:07,956 INFO [STDOUT] DEBUG SMTP:estel1212@yahoo.fr

2007-01-13 01:41:07,956 INFO [STDOUT] DEBUG SMTP: Sending failed because of invalid destination addresses

2007-01-13 01:41:07,956 INFO [STDOUT] RSET

2007-01-13 01:41:08,017 INFO [STDOUT] 250 2.0.0 Ok

2007-01-13 01:41:08,017 INFO [STDOUT] QUIT

2007-01-13 01:41:08,017 INFO [STDOUT] Error Sending:

2007-01-13 01:41:08,017 INFO [STDOUT] Sending failed;

nested exception is:

class javax.mail.SendFailedException: Invalid Addresses;

nested exception is:

class javax.mail.SendFailedException: 554 5.7.1 <estel1212@yahoo.fr>: Recipient address rejected: Access denied

2007-01-13 01:41:08,017 INFO [STDOUT] java.lang.NullPointerException

2007-01-13 01:41:08,017 INFO [STDOUT] at logicEJB.ejb.LogicBean.invokeEJBFunc(LogicBean.java:258)

radouane.marjania at 2007-7-8 8:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

For whatever reason, your mail server is rejecting the message.

You probably need to talk to the administrator of your mail server

to find out why.

I see that you've enabled SMTP authentication, but no authentication

is being done because the server doesn't advertise any authentication

mechanisms. That might be part of your problem, but again is a question

for your mail server administrator.

Perhaps you really need to connect over SSL so that the server will

allow you to send a password? That's more difficult with the older

version of JavaMail that's in JBoss. You'll need to search some older

forum or mailing list archives for instructions on how to do that.

bshannona at 2007-7-8 8:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Hi,

I don' think that a problem by Mailsever, that I must contact the admin.

I kann sending emails, when I try the same programm in a normal application with a main methode, just wenn I writte the same code in my ejb class, and I try to send the same email, that was already successful by a simple application, hier then I have the failure. I have seen by jboss deploy there is mail-service.xml, must I writte hier the propertys of my Mailserver and in my program use lookup like that:

InitialContext context = new InitialContext();

Session session = (Session) context.lookup("java:/Mail");

or I 'm free to do that like a standalone application like that:

Properties props = new Properties();

Session session = Session.getInstance(props, auth);

Have somone an idea, thanks,

Radouane

radouane.marjania at 2007-7-8 8:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Hi,

I want just writtefor you my javamail debug Infomationen by J2SE Application and bei J2EE application. By j2se was that sending successful, by j2ee application is a problem by TSL.

Hier Debug for j2se application:

-

DEBUG: setDebug: JavaMail version 1.4ea

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsys

tems, Inc]

DEBUG SMTP: useEhlo true, useAuth true

DEBUG SMTP: useEhlo true, useAuth true

DEBUG SMTP: trying to connect to host "mail.cs.tu-berlin.de", port 25, isSSL false

220 mailhost.cs.tu-berlin.de ESMTP Postfix

DEBUG SMTP: connected to host "mail.cs.tu-berlin.de", port: 25

EHLO meknes

250-mailhost.cs.tu-berlin.de

250-PIPELINING

250-SIZE

250-VRFY

250-ETRN

250-STARTTLS

250-ENHANCEDSTATUSCODES

250 8BITMIME

DEBUG SMTP: Found extension "PIPELINING", arg ""

DEBUG SMTP: Found extension "SIZE", arg ""

DEBUG SMTP: Found extension "VRFY", arg ""

DEBUG SMTP: Found extension "ETRN", arg ""

DEBUG SMTP: Found extension "STARTTLS", arg ""

DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""

DEBUG SMTP: Found extension "8BITMIME", arg ""

STARTTLS

220 2.0.0 Ready to start TLS

EHLO meknes

250-mailhost.cs.tu-berlin.de

250-PIPELINING

250-SIZE

250-VRFY

250-ETRN

250-AUTH PLAIN LOGIN

250-ENHANCEDSTATUSCODES

250 8BITMIME

DEBUG SMTP: Found extension "PIPELINING", arg ""

DEBUG SMTP: Found extension "SIZE", arg ""

DEBUG SMTP: Found extension "VRFY", arg ""

DEBUG SMTP: Found extension "ETRN", arg ""

DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"

DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""

DEBUG SMTP: Found extension "8BITMIME", arg ""

DEBUG SMTP: Attempt to authenticate

AUTH LOGIN

334 oioohbzfavsa7

mnhgvas8799800U=

30987hasabhsasa6

Y2hiijsasisas=

235 2.0.0 Authentication successful

DEBUG SMTP: use8bit false

MAIL FROM:<radouane@cs.tu-berlin.de>

250 2.1.0 Ok

RCPT TO:<estel1212@yahoo.fr>

250 2.1.5 Ok

DEBUG SMTP: Verified Addresses

DEBUG SMTP:estel1212@yahoo.fr

DATA

354 End data with <CR><LF>.<CR><LF>

From: radouane@cs.tu-berlin.de

To: estel1212@yahoo.fr

Message-ID: <9971081.01168741860633.JavaMail.radouane@meknes>

Subject: attachment

MIME-Version: 1.0

Content-Type: multipart/mixed;

boundary="-=_Part_0_25199001.1168741860423"

=_Part_0_25199001.1168741860423

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding: 7bit

Attachment Mail

=_Part_0_25199001.1168741860423

Content-Type: application/octet-stream; name=filename

Content-Transfer-Encoding: 7bit

Content-Disposition: attachment; filename=filename

--

Now by J2ee applicationI use jboss:

2007-01-14 03:27:28,769 INFO [STDOUT] DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]

2007-01-14 03:27:28,769 INFO [STDOUT] DEBUG SMTP: useEhlo true, useAuth true

2007-01-14 03:27:28,769 INFO [STDOUT] DEBUG SMTP: trying to connect to host "mail.cs.tu-berlin.de", port 25

2007-01-14 03:27:28,909 INFO [STDOUT] 220 mailhost.cs.tu-berlin.de ESMTP Postfix

2007-01-14 03:27:28,909 INFO [STDOUT] DEBUG SMTP: connected to host "mail.cs.tu-berlin.de", port: 25

2007-01-14 03:27:28,909 INFO [STDOUT] EHLO meknes

2007-01-14 03:27:28,979 INFO [STDOUT] 250-mailhost.cs.tu-berlin.de

250-PIPELINING

250-SIZE

250-VRFY

250-ETRN

250-STARTTLS

250-ENHANCEDSTATUSCODES

250 8BITMIME

2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "PIPELINING", arg ""

2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "SIZE", arg ""

2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "VRFY", arg ""

2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "ETRN", arg ""

2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "STARTTLS", arg ""

2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""

2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "8BITMIME", arg ""

2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: use8bit false

2007-01-14 03:27:28,979 INFO [STDOUT] MAIL FROM:<radouane@cs.tu-berlin.de>

2007-01-14 03:27:29,049 INFO [STDOUT] 250 2.1.0 Ok

2007-01-14 03:27:29,049 INFO [STDOUT] RCPT TO:<radouane@cs.tu-berlin.de>

2007-01-14 03:27:29,159 INFO [STDOUT] 554 5.7.1 <radouane@cs.tu-berlin.de>: Recipient address rejected: Access denied

2007-01-14 03:27:29,159 INFO [STDOUT] DEBUG SMTP: Invalid Addresses

2007-01-14 03:27:29,159 INFO [STDOUT] DEBUG SMTP:radouane@cs.tu-berlin.de

2007-01-14 03:27:29,159 INFO [STDOUT] DEBUG SMTP: Sending failed because of invalid destination addresses

2007-01-14 03:27:29,159 INFO [STDOUT] RSET

2007-01-14 03:27:29,229 INFO [STDOUT] 250 2.0.0 Ok

2007-01-14 03:27:29,229 INFO [STDOUT] QUIT

2007-01-14 03:27:29,229 INFO [STDOUT] Error Sending:

2007-01-14 03:27:29,229 INFO [STDOUT] Sending failed;

nested exception is:

class javax.mail.SendFailedException: Invalid Addresses;

nested exception is:

class javax.mail.SendFailedException: 554 5.7.1 <radouane@cs.tu-berlin.de>: Recipient address rejected: Access denied

2007-01-14 03:27:29,229 INFO [STDOUT] java.lang.NullPointerException

can someone tell me, where is my problem by j2ee application, it's a ejb class -using jboss-.

Thanks ,

Radouane

Message was edited by:

radouane.marjani

radouane.marjania at 2007-7-8 8:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
Hi,I have it!!I replaced mail.jar from server/default/lib with the latest version 1.4.(this version support SMTP+TLS) . that was. Now is all allright.Radouane
radouane.marjania at 2007-7-8 8:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...