JavaMail

JavaMail is a Java programming interface to platform - and protocol - independent send and receive emails. JavaMail supports the standard SMTP, POP3 and IMAP.

The JavaMail API is part of the Java EE platform, but can also be used as an optional package of the Java Standard Edition from.

Since 2 March 2009, JavaMail open source and can be used as JavaMail API Reference Implementation on the Kenai project related.

Use

Following is a code fragment for use JavaMail 1.4.4 with an SMTP server. The respective data are to be obtained from the provider.

Properties props = System.getProperties (); props.put ( " mail.smtp.host ", " SMTPHost "); props.put ( " mail.smtp.port ", " PORT NUMBER" ); props.put ( " mail.transport.protocol ", " smtp "); props.put ( " mail.smtp.auth ", "true "); props.put ( " mail.smtp.starttls.enable ", "true "); props.put ( " mail.smtp.tls ", "true "); props.put ( " mail.smtp.user ", " [email protected] "); props.put ( " mail.password ", " PASSWORD" );   javax.mail.Authenticator auth = new javax.mail.Authenticator () {     @ Override     public PasswordAuthentication getPasswordAuthentication () {        return new PasswordAuthentication ( " [email protected] ", " PASSWORD" );     } };   Session session = Session.getDefaultInstance ( props, auth);   Message msg = new MimeMessage (session ); msg.setFrom (new InternetAddress ( " [email protected] ", " EXAMPLENAME ")); msg.addRecipient ( Message.RecipientType.TO, new InternetAddress ( " [email protected] ", " TOEXAMPLE ")); msg.setSubject ( " SUBJECT" ); msg.setText ( "THE MESSAGE" ); msg.saveChanges (); Transport.send ( msg); alternatives

GNU JavaMail is another open source implementation of the Java Mail API. It implements JavaMail 1.3, and in addition to the protocols SMTP, IMAP and POP3 and NNTP, UNIX mbox and Dan Bernstein's Maildir format.

432168
de