//package com.carolinacustom; import javax.mail.*; import javax.mail.internet.*; import java.util.*; public class SendEmail { //----------------------------------------------------------------------------------- public void SendEmail() { } //----------------------------------------------------------------------------------- public static String SendMessage(String emailto, String emailfrom, String smtphost, String msgSubject, String is_multipart, String msgText1, String msgText1_type, String msgText2, String msgText2_type) { boolean debug = true; // change to get more information // set the host Properties props = new Properties(); //Properties props = System.getProperties(); props.put("mail.smtp.host", smtphost); //props.put("mail.smtp.host", "mail.carolinacustom.com"); //props.put("mail.smtp.port", "25"); props.put("mail.smtp.debug", "true"); //props.put("mail.smtp.user", "scdemarc"); // create some properties and get the default Session Session session = Session.getDefaultInstance(props, null); session.setDebug(debug); try { // create a message Message msg = new MimeMessage(session); // set the from InternetAddress from = new InternetAddress(emailfrom); msg.setFrom(from); InternetAddress[] address = { new InternetAddress(emailto) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(msgSubject); if(!(Boolean.valueOf(is_multipart).booleanValue())) { // send a plain text message msg.setContent(msgText1, msgText1_type); } else { // send a multipart message// create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setContent(msgText1, msgText1_type); // create and fill the second message part MimeBodyPart mbp2 = new MimeBodyPart(); mbp2.setContent(msgText2, msgText2_type); // create the Multipart and its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); } Transport.send(msg); } catch(MessagingException mex) { mex.printStackTrace(); } return "Email sent to " + emailto; } public static void main(String[] args) { String email_subject; String email_message1; String email_message2; email_subject = "Carolina Custom order confirmation, "; email_message1 = "this is just the text part of the email"; email_message2 = ""; email_message2 += "\n"; email_message2 += "\n"; email_message2 += "\n"; email_message2 += "\n"; email_message2 += "
\n"; email_message2 += " \n"; email_message2 += " \n"; email_message2 += " \n"; email_message2 += " \n"; email_message2 += "
\n"; email_message2 += "
\n"; email_message2 += "\n"; email_message2 += "\n"; //SendMessage("scdemarc@unity.ncsu.edu", "chris@carolinacustom.com", "smtp-server.nc.rr.com", email_subject, "true", // email_message1, "text/plain", email_message2, "text/html"); SendMessage("scdemarc@yahoo.com", "chris@carolinacustom.com", "mail.carolinacustom.com", email_subject, "true", email_message1, "text/plain", email_message2, "text/html"); } }