// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and 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.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class SendMultipartEmail {
    public static void main(String[] args) {
        sendMultipartEmail();
    }
    public static void sendMultipartEmail() {
        try {
            Properties props = System.getProperties();
            props.put("mail.smtp.host", "192.168.1.10");
            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");
            MimeBodyPart mpart1 = new MimeBodyPart();
            mpart1.setText("Linie 1\n" +
                           "Linie 2");
            MimeBodyPart mpart2 = new MimeBodyPart();
            mpart2.setContent("<H1>Overskrift</H1>\n" +
                              "Billede:\n" +
                              "<IMG SRC='http://www.eksperten.dk/img/eksperten_logo_new.gif'>",
                              "text/html");
            MimeMultipart mpart = new MimeMultipart();
            mpart.addBodyPart(mpart1);
            mpart.addBodyPart(mpart2);
            message.setContent(mpart);
            Transport.send(message);
        } catch (AddressException e) {
        } catch (MessagingException e) {
        }
    }
}
