// Collection of code snippets by Arne Vajhøj // posted to eksperten.dk, usenet and other places (2002-now) import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class SendEmail { public static void main(String[] args) { sendTextEmail(); sendHtmlEmail(); } public static void sendTextEmail() { try { Properties props = System.getProperties(); props.put("mail.smtp.host", "x.x.x.x"); Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress("nn@somewhere.dk")); message.addRecipient(Message.RecipientType.TO, new InternetAddress("nn@somewhere.dk")); message.setSubject("Test"); message.setText("Dette er en test\n" + "Næste linie"); Transport.send(message); } catch (AddressException e) { } catch (MessagingException e) { } } public static void sendHtmlEmail() { try { Properties props = System.getProperties(); props.put("mail.smtp.host", "x.x.x.x"); Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress("nn@somewhere.dk")); message.addRecipient(Message.RecipientType.TO, new InternetAddress("nn@somewhere.dk")); message.setSubject("Test"); message.setContent("