package com.tutego.insel.mail;

import java.util.Properties;

import javax.mail.*;
import javax.mail.internet.*;

public class SendJavaMail
{
  public static void postMail( String recipient,
							                 String subject,
							                 String message, String from )
	  throws MessagingException
  {
		Properties props = new Properties();
    props.put( "mail.smtp.host", "mail.mailserver.com" );

		Session session = Session.getDefaultInstance( props );

		Message msg = new MimeMessage( session );

		InternetAddress addressFrom = new InternetAddress( from );
		msg.setFrom( addressFrom );

		InternetAddress addressTo = new InternetAddress( recipient );
		msg.setRecipient( Message.RecipientType.TO, addressTo );

		msg.setSubject( subject );
		msg.setContent( message, "text/plain" );
		Transport.send( msg );
  }

  public static void main( String[] args ) throws Exception
  {
    postMail( "Buchtest@mailserver.com",
              "Tolles Buch",
              "Wow. Das Buch ist schön zu lesen",
              "info@mailserver.com" );
  }
}
