Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - Sending mail with Javamail over ssl...

 
Thread Tools Search this Thread
Old 06-12-2006, 03:08 PM   #1
Default Sending mail with Javamail over ssl...


Hi,

are there any tutorials for sending a mail with Javamail (1.4 Release)?

I've tried it on my own with SMTPSSLTranport with no success... It's
driving me nuts...


Thanks in andvance and best regards.

Carsten Marx



carsten801
  Reply With Quote
Old 06-12-2006, 03:29 PM   #2
Thomas Weidenfeller
 
Posts: n/a
Default Re: Sending mail with Javamail over ssl...
carsten801 wrote:
> are there any tutorials for sending a mail with Javamail (1.4 Release)?


Check your JavaMail installation directory. The docs subdirectory should
contain the design spec (in PostScript and pdf), which explains how the
components interact. The demo subdirectory contains 10+ example
applications.

/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/


Thomas Weidenfeller
  Reply With Quote
Old 06-12-2006, 05:22 PM   #3
carsten801
 
Posts: n/a
Default Re: Sending mail with Javamail over ssl...

Thomas Weidenfeller wrote:
> carsten801 wrote:
> > are there any tutorials for sending a mail with Javamail (1.4 Release)?

>
> Check your JavaMail installation directory. The docs subdirectory should
> contain the design spec (in PostScript and pdf), which explains how the
> components interact. The demo subdirectory contains 10+ example
> applications.
>
> /Thomas
> --
> The comp.lang.java.gui FAQ:
> ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
> http://www.uni-giessen.de/faq/archiv....java.gui.faq/


I've checked the installation directory. So i've written a method like
this:


<code>
private void sendMail() {
MainFrame.get().setCursor(Preferences.WAIT_CURSOR) ;
String adr = address.getText();
try {
// create properties
Properties props = System.getProperties();
props.put("mail.smtps.auth", "true");
props.put("mail.smtps.port", "25");
props.put("mail.smtps.host", Preferences.MAIL_HOST);
// create session
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
// create content
MimeMultipart content = new MimeMultipart("alternative");
// Text Mail
MimeBodyPart plain = new MimeBodyPart();
plain.setContent(plainText, "text/plain");
plain.setHeader("MIME-Version", "1.0");
plain.setHeader("Content-Type", "text/plain;
charset=\"iso-8859-1\"");
content.addBodyPart(plain);
// HTML Mail
MimeBodyPart html = new MimeBodyPart();
html.setContent(htmlText, "text/html");
html.setHeader("MIME-Version", "1.0");
html.setHeader("Content-Type", "text/html;
charset=\"iso-8859-1\"");
content.addBodyPart(html);
// create message
MimeMessage msg = new MimeMessage(session);
msg.setContent(content);
msg.setHeader("MIME-Version", "1.0");
msg.setHeader("Content-Type", content.getContentType());
msg.setHeader("X-Mailer", "Java-Mailer");
msg.setSentDate(new Date());
// set sender and recipient
msg.setFrom(new InternetAddress(Preferences.MAIL_FROM,
Preferences.MAIL_SENDER));
msg.addRecipient(Message.RecipientType.TO, new
InternetAddress(adr));
msg.setSubject(Texts.MAIL_SUBJECT);
// save changes
msg.saveChanges();
// transport the message
SMTPSSLTransport transport =
(SMTPSSLTransport)session.getTransport("smtps");
// get password
String pwNew = DataManager.code(Preferences.MAIL_PASSWORD);
// connect to server
// send the message
transport.connect(Preferences.MAIL_HOST, Preferences.MAIL_LOGIN,
pwNew);
transport.sendMessage(msg, msg.getAllRecipients());
// close the connection
transport.close();
} catch (Exception e) {
e.getStackTrace();
ErrorManager.mailError(MainFrame.get());
return;
} finally {
MainFrame.get().setCursor(Preferences.DEFAULT_CURS OR);
dispose();
}
ErrorManager.mailSent(MainFrame.get());
}
</code>


But this isn't working (Yes the port 25 is ok for ssl connection, with
Mail.app this account is working).

Here the debug stack trace:
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning
javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport ,Sun
Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "xxx-my.mail.host-xxx", port 25,
isSSL true
DEBUG SMTP: exception reading response: javax.net.ssl.SSLException:
Unrecognized SSL message, plaintext connection?


Bug? Or am i blind?

Best regards

Carsten



carsten801
  Reply With Quote
Old 06-13-2006, 04:46 PM   #4
Greg R. Broderick
 
Posts: n/a
Default Re: Sending mail with Javamail over ssl...
"carsten801" <> wrote in
news: oups.com:

> Here the debug stack trace:
> DEBUG: setDebug: JavaMail version 1.4ea
> DEBUG: getProvider() returning
> javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTranspor
> t,Sun Microsystems, Inc]
> DEBUG SMTP: useEhlo true, useAuth true
> DEBUG SMTP: trying to connect to host "xxx-my.mail.host-xxx", port
> 25, isSSL true
> DEBUG SMTP: exception reading response: javax.net.ssl.SSLException:
> Unrecognized SSL message, plaintext connection?
>


Try using the SMTPS port (465) instead of the SMTP port (25).

Cheers
GRB


Greg R. Broderick
  Reply With Quote
Old 02-03-2009, 07:21 AM   #5
dfx
Junior Member
 
Join Date: Feb 2009
Posts: 1
Default mail over SSL
<my properties>
props.setProperty("mail.transport.protocol", "smtps");
props.put("mail.smtps.auth", "true");
props.put("mail.smtps.port", "465");
props.put("mail.smtps.host", this.strMailHost);

<Strack Trace Error>

DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport ,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "exch.pdea.gov.ph", port 465, isSSL true
Got Exception: javax.mail.MessagingException: Could not connect to SMTP host: exch.pdea.gov.ph, port: 465;
nested exception is:
java.net.SocketException: Network is unreachable: connect
Got Exception: javax.mail.MessagingException: Could not connect to SMTP host: exch.pdea.gov.ph, port: 465;
nested exception is:
java.net.SocketException: Network is unreachable: connect


dfx
dfx is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
sending mail susan_1516 Software 0 11-09-2008 01:29 PM
Windows Mail Neil MCTS 2 11-04-2007 02:51 AM
Mail Server clavox Software 0 09-06-2006 11:58 PM
Re: Virus Problem ** Help!** David BlandIII A+ Certification 1 03-02-2004 06:00 PM
Got my certificate in the mail - what a joke! Jinkies A+ Certification 20 12-28-2003 08:38 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46