<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Mikehale's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 05:19:30 GMT</pubDate>
    <description>DZone Snippets: Mikehale's Code Snippets</description>
    <item>
      <title>Make sure your site (or directory) is SSL encrypted</title>
      <link>http://snippets.dzone.com/posts/show/4405</link>
      <description>Need a simple way to make sure all http requests get redirected to https?&lt;br /&gt;This apache config snippet will redirect all requests at or below the specified location to its https equivilant.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;Location "/"&gt;&lt;br /&gt;        RewriteEngine on&lt;br /&gt;        Options +FollowSymLinks&lt;br /&gt;        Allow from all&lt;br /&gt;        RewriteCond %{SERVER_PORT} !^443$&lt;br /&gt;        RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]&lt;br /&gt;&lt;/Location&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 09 Aug 2007 17:52:54 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4405</guid>
      <author>mikehale (Michael Hale)</author>
    </item>
    <item>
      <title>Authenticate with SMTP server before sending email</title>
      <link>http://snippets.dzone.com/posts/show/3328</link>
      <description>For more info see: http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html&lt;br /&gt;&lt;br /&gt;You need activation.jar, smtp.jar, and mailapi.jar in your classpath for this to work.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import java.util.Properties;&lt;br /&gt;&lt;br /&gt;import javax.mail.Message;&lt;br /&gt;import javax.mail.MessagingException;&lt;br /&gt;import javax.mail.PasswordAuthentication;&lt;br /&gt;import javax.mail.Session;&lt;br /&gt;import javax.mail.Transport;&lt;br /&gt;import javax.mail.internet.InternetAddress;&lt;br /&gt;import javax.mail.internet.MimeMessage;&lt;br /&gt;import javax.mail.internet.MimeMessage.RecipientType;&lt;br /&gt;&lt;br /&gt;public class MailWithPasswordAuthentication {&lt;br /&gt;	public static void main(String[] args) throws MessagingException {&lt;br /&gt;		new MailWithPasswordAuthentication().run();&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	private void run() throws MessagingException {&lt;br /&gt;		Message message = new MimeMessage(getSession());&lt;br /&gt;&lt;br /&gt;		message.addRecipient(RecipientType.TO, new InternetAddress("to@example.com"));&lt;br /&gt;		message.addFrom(new InternetAddress[] { new InternetAddress("from@example.com") });&lt;br /&gt;&lt;br /&gt;		message.setSubject("the subject");&lt;br /&gt;		message.setContent("the body", "text/plain");&lt;br /&gt;&lt;br /&gt;		Transport.send(message);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	private Session getSession() {&lt;br /&gt;		Authenticator authenticator = new Authenticator();&lt;br /&gt;&lt;br /&gt;		Properties properties = new Properties();&lt;br /&gt;		properties.setProperty("mail.smtp.submitter", authenticator.getPasswordAuthentication().getUserName());&lt;br /&gt;		properties.setProperty("mail.smtp.auth", "true");&lt;br /&gt;&lt;br /&gt;		properties.setProperty("mail.smtp.host", "mail.example.com");&lt;br /&gt;		properties.setProperty("mail.smtp.port", "25");&lt;br /&gt;&lt;br /&gt;		return Session.getInstance(properties, authenticator);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	private class Authenticator extends javax.mail.Authenticator {&lt;br /&gt;		private PasswordAuthentication authentication;&lt;br /&gt;&lt;br /&gt;		public Authenticator() {&lt;br /&gt;			String username = "auth-user";&lt;br /&gt;			String password = "auth-password";&lt;br /&gt;			authentication = new PasswordAuthentication(username, password);&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;		protected PasswordAuthentication getPasswordAuthentication() {&lt;br /&gt;			return authentication;&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 19 Jan 2007 00:55:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3328</guid>
      <author>mikehale (Michael Hale)</author>
    </item>
  </channel>
</rss>
