Example usage for javax.mail Message setSubject

List of usage examples for javax.mail Message setSubject

Introduction

In this page you can find the example usage for javax.mail Message setSubject.

Prototype

public abstract void setSubject(String subject) throws MessagingException;

Source Link

Document

Set the subject of this message.

Usage

From source file:dk.netarkivet.common.utils.EMailUtils.java

/**
 * Send an email, possibly forgiving errors.
 *
 * @param to The recipient of the email. Separate multiple recipients with
 *           commas. Supports only adresses of the type 'john@doe.dk', not
 *           'John Doe <john@doe.dk>'
 * @param from The sender of the email./*from   ww w  .ja  v  a  2 s .  c o m*/
 * @param subject The subject of the email.
 * @param body The body of the email.
 * @param forgive On true, will send the email even on invalid email
 *        addresses, if at least one recipient can be set, on false, will
 *        throw exceptions on any invalid email address.
 *
 *
 * @throws ArgumentNotValid If either parameter is null, if to, from or
 *                          subject is the empty string, or no recipient
 *                          can be set. If "forgive" is false, also on
 *                          any invalid to or from address.
 * @throws IOFailure If the message cannot be sent for some reason.
 */
public static void sendEmail(String to, String from, String subject, String body, boolean forgive) {
    ArgumentNotValid.checkNotNullOrEmpty(to, "String to");
    ArgumentNotValid.checkNotNullOrEmpty(from, "String from");
    ArgumentNotValid.checkNotNullOrEmpty(subject, "String subject");
    ArgumentNotValid.checkNotNull(body, "String body");

    Properties props = new Properties();
    props.put(MAIL_FROM_PROPERTY_KEY, from);
    props.put(MAIL_HOST_PROPERTY_KEY, Settings.get(CommonSettings.MAIL_SERVER));

    Session session = Session.getDefaultInstance(props);
    Message msg = new MimeMessage(session);

    // to might contain more than one e-mail address
    for (String toAddressS : to.split(",")) {
        try {
            InternetAddress toAddress = new InternetAddress(toAddressS.trim());
            msg.addRecipient(Message.RecipientType.TO, toAddress);
        } catch (AddressException e) {
            if (forgive) {
                log.warn("To address '" + toAddressS + "' is not a valid email " + "address", e);
            } else {
                throw new ArgumentNotValid("To address '" + toAddressS + "' is not a valid email " + "address",
                        e);
            }
        } catch (MessagingException e) {
            if (forgive) {
                log.warn("To address '" + toAddressS + "' could not be set in email", e);
            } else {
                throw new ArgumentNotValid("To address '" + toAddressS + "' could not be set in email", e);
            }
        }
    }
    try {
        if (msg.getAllRecipients().length == 0) {
            throw new ArgumentNotValid("No valid recipients in '" + to + "'");
        }
    } catch (MessagingException e) {
        throw new ArgumentNotValid("Message invalid after setting" + " recipients", e);
    }

    try {
        InternetAddress fromAddress = null;
        fromAddress = new InternetAddress(from);
        msg.setFrom(fromAddress);
    } catch (AddressException e) {
        throw new ArgumentNotValid("From address '" + from + "' is not a valid email " + "address", e);
    } catch (MessagingException e) {
        if (forgive) {
            log.warn("From address '" + from + "' could not be set in email", e);
        } else {
            throw new ArgumentNotValid("From address '" + from + "' could not be set in email", e);
        }
    }

    try {
        msg.setSubject(subject);
        msg.setContent(body, MIMETYPE);
        msg.setSentDate(new Date());
        Transport.send(msg);
    } catch (MessagingException e) {
        throw new IOFailure("Could not send email with subject '" + subject + "' from '" + from + "' to '" + to
                + "'. Body:\n" + body, e);
    }
}

From source file:it.infn.ct.security.utilities.LDAPCleaner.java

private void sendUserRemainder(UserRequest ur, int days) {
    javax.mail.Session session = null;//w ww .  jav a 2  s.  co  m
    try {
        Context initCtx = new InitialContext();
        Context envCtx = (Context) initCtx.lookup("java:comp/env");
        session = (javax.mail.Session) envCtx.lookup("mail/Users");

        Message mailMsg = new MimeMessage(session);
        mailMsg.setFrom(new InternetAddress(rb.getString("mailSender"), rb.getString("IdPAdmin")));

        InternetAddress mailTo[] = new InternetAddress[1];
        mailTo[0] = new InternetAddress(getGoodMail(ur),
                ur.getTitle() + " " + ur.getGivenname() + " " + ur.getSurname());
        mailMsg.setRecipients(Message.RecipientType.TO, mailTo);

        if (rb.containsKey("mailCopy") && !rb.getString("mailCopy").isEmpty()) {

            String ccMail[] = rb.getString("mailCopy").split(";");
            InternetAddress mailCCopy[] = new InternetAddress[ccMail.length];
            for (int i = 0; i < ccMail.length; i++) {
                mailCCopy[i] = new InternetAddress(ccMail[i]);
            }

            mailMsg.setRecipients(Message.RecipientType.CC, mailCCopy);
        }

        if (days > 0) {
            mailMsg.setSubject(
                    rb.getString("mailNotificationSubject").replace("_DAYS_", Integer.toString(days)));
            mailMsg.setText(rb.getString("mailNotificationBody")
                    .replaceAll("_USER_", ur.getTitle() + " " + ur.getGivenname() + " " + ur.getSurname())
                    .replace("_DAYS_", Integer.toString(days)));
        } else {
            mailMsg.setSubject(rb.getString("mailDeleteSubject").replace("_DAYS_", Integer.toString(days)));
            mailMsg.setText(rb.getString("mailDeleteBody")
                    .replaceAll("_USER_", ur.getTitle() + " " + ur.getGivenname() + " " + ur.getSurname())
                    .replace("_DAYS_", Integer.toString(days)));
        }
        Transport.send(mailMsg);

    } catch (Exception ex) {
        _log.error("Mail resource lookup error");
        _log.error(ex.getMessage());
    }
}

From source file:com.nridge.core.app.mail.MailManager.java

/**
 * If the property "delivery_enabled" is <i>true</i>, then this method
 * will generate an email message that includes subject, message and
 * attachments to the recipient list.  You can use the convenience
 * methods <i>lookupFromAddress()</i>, <i>createRecipientList()</i>
 * and <i>createAttachmentList()</i> for parameter building assistance.
 *
 * @param aFromAddress Source email address.
 * @param aRecipientList List of recipient email addresses.
 * @param aSubject Subject of the email message.
 * @param aMessage Messsage.//from   www.j  ava  2s . com
 * @param anAttachmentFiles List of file attachments or <i>null</i> for none.
 *
 * @see <a href="https://www.tutorialspoint.com/javamail_api/javamail_api_send_email_with_attachment.htm">JavaMail API Attachments</a>
 * @see <a href="https://stackoverflow.com/questions/6756162/how-do-i-send-mail-with-both-plain-text-as-well-as-html-text-so-that-each-mail-r">JavaMail API MIME Types</a>
 *
 * @throws IOException I/O related error condition.
 * @throws NSException Missing configuration properties.
 * @throws MessagingException Message subsystem error condition.
 */
public void sendMessage(String aFromAddress, ArrayList<String> aRecipientList, String aSubject, String aMessage,
        ArrayList<String> anAttachmentFiles)

        throws IOException, NSException, MessagingException {
    InternetAddress internetAddressFrom, internetAddressTo;
    Logger appLogger = mAppMgr.getLogger(this, "sendMessage");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    if (isCfgStringTrue("delivery_enabled")) {
        if ((StringUtils.isNotEmpty(aFromAddress)) && (aRecipientList.size() > 0)
                && (StringUtils.isNotEmpty(aSubject)) && (StringUtils.isNotEmpty(aMessage))) {
            initialize();

            Message mimeMessage = new MimeMessage(mMailSession);
            internetAddressFrom = new InternetAddress(aFromAddress);
            mimeMessage.addFrom(new InternetAddress[] { internetAddressFrom });
            for (String mailAddressTo : aRecipientList) {
                internetAddressTo = new InternetAddress(mailAddressTo);
                mimeMessage.addRecipient(MimeMessage.RecipientType.TO, internetAddressTo);
            }
            mimeMessage.setSubject(aSubject);

            // The following logic create a multi-part message and adds the attachment to it.

            BodyPart messageBodyPart = new MimeBodyPart();
            messageBodyPart.setText(aMessage);
            //                messageBodyPart.setContent(aMessage, "text/html");
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messageBodyPart);

            if ((anAttachmentFiles != null) && (anAttachmentFiles.size() > 0)) {
                for (String pathFileName : anAttachmentFiles) {
                    File attachmentFile = new File(pathFileName);
                    if (attachmentFile.exists()) {
                        messageBodyPart = new MimeBodyPart();
                        DataSource fileDataSource = new FileDataSource(pathFileName);
                        messageBodyPart.setDataHandler(new DataHandler(fileDataSource));
                        messageBodyPart.setFileName(attachmentFile.getName());
                        multipart.addBodyPart(messageBodyPart);
                    }
                }
                appLogger.debug(String.format("Mail Message (%s): %s - with attachments", aSubject, aMessage));
            } else
                appLogger.debug(String.format("Mail Message (%s): %s", aSubject, aMessage));

            mimeMessage.setContent(multipart);
            Transport.send(mimeMessage);
        } else
            throw new NSException("Valid from, recipient, subject and message are required parameters.");
    } else
        appLogger.warn("Email delivery is not enabled - no message will be sent.");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

From source file:org.roda.core.util.EmailUtility.java

/**
 * @param from//w  w w . j a  v  a2s  .c  om
 * @param recipients
 * @param subject
 * @param message
 * @throws MessagingException
 */
public void sendMail(String from, String recipients[], String subject, String message)
        throws MessagingException {
    boolean debug = false;

    // Set the host smtp address
    Properties props = new Properties();
    props.put("mail.smtp.host", this.smtpHost);

    // create some properties and get the default Session
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(debug);

    // create a message
    Message msg = new MimeMessage(session);

    // set the from and to address
    InternetAddress addressFrom = new InternetAddress(from);
    msg.setFrom(addressFrom);

    InternetAddress[] addressTo = new InternetAddress[recipients.length];
    for (int i = 0; i < recipients.length; i++) {
        addressTo[i] = new InternetAddress(recipients[i]);
    }
    msg.setRecipients(Message.RecipientType.TO, addressTo);

    // Optional : You can also set your custom headers in the Email if you
    // want
    // msg.addHeader("MyHeaderName", "myHeaderValue");

    String htmlMessage = String.format(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<html><body><pre>%s</pre></body></html>",
            StringEscapeUtils.escapeHtml4(message));

    MimeMultipart mimeMultipart = new MimeMultipart();
    MimeBodyPart mimeBodyPart = new MimeBodyPart();
    mimeBodyPart.setContent(htmlMessage, "text/html;charset=UTF-8");
    mimeMultipart.addBodyPart(mimeBodyPart);

    // Setting the Subject and Content Type
    msg.setSubject(subject);
    msg.setContent(mimeMultipart);
    // msg.setContent(message, "text/plain;charset=UTF-8");
    Transport.send(msg);
}

From source file:org.springfield.lou.application.types.EuscreenxlitemApplication.java

public void sendContentProviderMail(Screen s, String data) {
    //System.out.println("Send mail to CP: " + data);

    JSONObject form = (JSONObject) JSONValue.parse(data);

    String mailfrom = "euscreen-portal@noterik.nl";
    String mailsubject = "Somebody showed interest in your item on EUScreen";
    String email = (String) form.get("email");
    String id = (String) form.get("identifier");
    String provider = (String) form.get("provider");
    String subject = (String) form.get("subject");
    String title = (String) form.get("title");
    String message = (String) form.get("message");
    message = message.replaceAll("(\r\n|\n)", "<br />");

    //Form validation
    JSONObject mailResponse = new JSONObject();
    Set<String> keys = form.keySet();
    boolean errors = false;
    for (String key : keys) {
        String value = (String) form.get(key);
        if (value == null || value.isEmpty()) {
            errors = true;//from  w w w  .  j av a 2 s.c o  m
            break;
        }
    }

    if (errors) {
        mailResponse.put("status", "false");
        mailResponse.put("message", "Please fill in all the fields.");
        s.putMsg("copyright", "", "showMailResponse(" + mailResponse + ")");
        return;
    }

    String toemail = null;
    //Find the provider email
    FsNode providerNode = Fs.getNode("/domain/euscreenxl/user/" + provider + "/account/default");
    toemail = providerNode.getProperty("email");

    String body = "Identifier: " + id + "<br/>";
    body += "Title: " + title + "<br/>";
    body += "Link to item on EUScreen:<br/>";
    body += "<a href=\"http://euscreen.eu/item.html?id=" + id + "\">http://euscreen.eu/item.html?id=" + id
            + "</a><br/>";
    body += "-------------------------------------------<br/><br/>";
    body += "Subject: " + subject + "<br/>";
    body += "Message:<br/>";
    body += message + "<br/><br/>";
    body += "-------------------------------------------<br/>";
    body += "You can contact the sender of this message on: <a href=\"mailto:" + email + "\">" + email
            + "</a><br/>";

    if (this.inDevelMode()) { //In devel mode always send the email to the one filled in the form
        toemail = email;
    }

    //!!! Hack to send the email to the one filled in the form (for testing purposes). When on production it should be removed
    //toemail = email;

    boolean success = true;
    if (toemail != null) {
        try {
            Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            Session session = (Session) envCtx.lookup("mail/Session");

            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(mailfrom));
            InternetAddress to[] = new InternetAddress[1];
            to[0] = new InternetAddress(toemail);
            msg.setRecipients(Message.RecipientType.TO, to);

            InternetAddress bcc[] = new InternetAddress[1];
            bcc[0] = new InternetAddress("r.rozendal@noterik.nl");
            msg.setRecipients(Message.RecipientType.BCC, bcc);

            msg.setSubject(mailsubject);
            msg.setContent(body, "text/html");
            Transport.send(msg);
        } catch (Exception e) {
            System.out.println("Failed sending email: " + e);
            success = false;
        }
    } else {
        success = false;
    }

    String response = "Your message has been successfuly sent.";
    if (!success)
        response = "There was a problem sending your mail.<br/>Please try again later.";

    mailResponse.put("status", Boolean.toString(success));
    mailResponse.put("message", response);

    s.putMsg("copyright", "", "showMailResponse(" + mailResponse + ")");

}

From source file:com.liferay.mail.imap.IMAPAccessor.java

protected Message createMessage(String personalName, String sender, Address[] to, Address[] cc, Address[] bcc,
        String subject, String body, List<MailFile> mailFiles)
        throws MessagingException, UnsupportedEncodingException {

    Message jxMessage = new MimeMessage(_imapConnection.getSession());

    jxMessage.setFrom(new InternetAddress(sender, personalName));
    jxMessage.addRecipients(Message.RecipientType.TO, to);
    jxMessage.addRecipients(Message.RecipientType.CC, cc);
    jxMessage.addRecipients(Message.RecipientType.BCC, bcc);
    jxMessage.setSentDate(new Date());
    jxMessage.setSubject(subject);

    MimeMultipart multipart = new MimeMultipart();

    BodyPart messageBodyPart = new MimeBodyPart();

    messageBodyPart.setContent(body, ContentTypes.TEXT_HTML_UTF8);

    multipart.addBodyPart(messageBodyPart);

    if (mailFiles != null) {
        for (MailFile mailFile : mailFiles) {
            File file = mailFile.getFile();

            if (!file.exists()) {
                continue;
            }/* w  ww  . ja va 2  s  . c  om*/

            DataSource dataSource = new FileDataSource(file);

            BodyPart attachmentBodyPart = new MimeBodyPart();

            attachmentBodyPart.setDataHandler(new DataHandler(dataSource));
            attachmentBodyPart.setFileName(mailFile.getFileName());

            multipart.addBodyPart(attachmentBodyPart);
        }
    }

    jxMessage.setContent(multipart);

    return jxMessage;
}

From source file:Mailer.java

/** Send the message.
 *///from www.  j a  v  a2s.  c o m
public synchronized void doSend() throws MessagingException {

    if (!isComplete())
        throw new IllegalArgumentException("doSend called before message was complete");

    /** Properties object used to pass props into the MAIL API */
    Properties props = new Properties();
    props.put("mail.smtp.host", mailHost);

    // Create the Session object
    if (session == null) {
        session = Session.getDefaultInstance(props, null);
        if (verbose)
            session.setDebug(true); // Verbose!
    }

    // create a message
    final Message mesg = new MimeMessage(session);

    InternetAddress[] addresses;

    // TO Address list
    addresses = new InternetAddress[toList.size()];
    for (int i = 0; i < addresses.length; i++)
        addresses[i] = new InternetAddress((String) toList.get(i));
    mesg.setRecipients(Message.RecipientType.TO, addresses);

    // From Address
    mesg.setFrom(new InternetAddress(from));

    // CC Address list
    addresses = new InternetAddress[ccList.size()];
    for (int i = 0; i < addresses.length; i++)
        addresses[i] = new InternetAddress((String) ccList.get(i));
    mesg.setRecipients(Message.RecipientType.CC, addresses);

    // BCC Address list
    addresses = new InternetAddress[bccList.size()];
    for (int i = 0; i < addresses.length; i++)
        addresses[i] = new InternetAddress((String) bccList.get(i));
    mesg.setRecipients(Message.RecipientType.BCC, addresses);

    // The Subject
    mesg.setSubject(subject);

    // Now the message body.
    mesg.setText(body);

    // Finally, send the message! (use static Transport method)
    // Do this in a Thread as it sometimes is too slow for JServ
    // new Thread() {
    // public void run() {
    // try {

    Transport.send(mesg);

    // } catch (MessagingException e) {
    // throw new IllegalArgumentException(
    // "Transport.send() threw: " + e.toString());
    // }
    // }
    // }.start();
}

From source file:org.sofun.platform.notification.NotificationServiceImpl.java

@Override
public void sendEmail(Member member, Map<String, String> params) throws CoreException {

    final String emailsStr = params.get("emails");
    String[] emails = null;//from w w  w.ja v  a2 s  . c  o  m
    if (emailsStr != null) {
        emails = params.get("emails").split(",");
    }

    String format = params.get("format");
    if (format == null) {
        format = "text/html";
    }
    Message message = new MimeMessage(mailer);

    final String encodingOptions = format + "; charset=UTF-8";
    try {
        message.setHeader("Content-Type", encodingOptions);

        String from = params.get("from");
        if (from == null || from.equals("")) {
            message.setFrom(new InternetAddress(CoreConstants.SOFUN_MAIL_FROM));
        } else {
            message.setFrom(new InternetAddress(from));
        }

        InternetAddress to[] = null;
        if (emails == null) {
            to = new InternetAddress[1];
            to[0] = new InternetAddress(member.getEmail());
        } else {
            to = new InternetAddress[emails.length];
            for (int i = 0; i < emails.length; i++) {
                to[i] = new InternetAddress(emails[i]);
            }
        }

        message.setRecipients(Message.RecipientType.TO, to);
        message.setSubject(params.get("subject"));

        String body = params.get("body");
        if (body != null) {
            body = body.replaceAll("(\\r|\\n)", "<p/>");
        }

        VelocityEngine ve = null;
        try {
            ve = getVelocityEngine();
        } catch (Exception e) {
            throw new CoreException(e.getMessage());
        }

        Template t = ve.getTemplate(params.get("templateId"));
        StringWriter writer = new StringWriter();

        VelocityContext context = new VelocityContext();

        // Add Member in velocity context.
        context.put("member", member);
        context.put("body", body);

        // Add all incoming params in velocity context.
        for (Map.Entry<String, String> entry : params.entrySet()) {
            context.put(entry.getKey(), entry.getValue());
        }

        t.merge(context, writer);

        message.setContent(writer.toString(), encodingOptions);
        Transport.send(message);
        String logEmails;
        if (emails != null) {
            logEmails = emailsStr;
        } else {
            logEmails = member.getEmail();
        }
        log.info("Sending an email to=" + logEmails);
    } catch (MessagingException e) {
        log.error("Failed to send an email. See error below.");
        throw new CoreException(e.getMessage());
    }

}

From source file:org.apache.roller.weblogger.util.MailUtil.java

/**
 * This method is used to send a Message with a pre-defined
 * mime-type./*from   w  w  w .ja  va 2s.c o  m*/
 *
 * @param from e-mail address of sender
 * @param to e-mail address(es) of recipients
 * @param subject subject of e-mail
 * @param content the body of the e-mail
 * @param mimeType type of message, i.e. text/plain or text/html
 * @throws MessagingException the exception to indicate failure
 */
public static void sendMessage(String from, String[] to, String[] cc, String[] bcc, String subject,
        String content, String mimeType) throws MessagingException {

    MailProvider mailProvider = WebloggerStartup.getMailProvider();
    if (mailProvider == null) {
        return;
    }

    Session session = mailProvider.getSession();
    Message message = new MimeMessage(session);

    // n.b. any default from address is expected to be determined by caller.
    if (!StringUtils.isEmpty(from)) {
        InternetAddress sentFrom = new InternetAddress(from);
        message.setFrom(sentFrom);
        if (log.isDebugEnabled())
            log.debug("e-mail from: " + sentFrom);
    }

    if (to != null) {
        InternetAddress[] sendTo = new InternetAddress[to.length];

        for (int i = 0; i < to.length; i++) {
            sendTo[i] = new InternetAddress(to[i]);
            if (log.isDebugEnabled())
                log.debug("sending e-mail to: " + to[i]);
        }
        message.setRecipients(Message.RecipientType.TO, sendTo);
    }

    if (cc != null) {
        InternetAddress[] copyTo = new InternetAddress[cc.length];

        for (int i = 0; i < cc.length; i++) {
            copyTo[i] = new InternetAddress(cc[i]);
            if (log.isDebugEnabled())
                log.debug("copying e-mail to: " + cc[i]);
        }
        message.setRecipients(Message.RecipientType.CC, copyTo);
    }

    if (bcc != null) {
        InternetAddress[] copyTo = new InternetAddress[bcc.length];

        for (int i = 0; i < bcc.length; i++) {
            copyTo[i] = new InternetAddress(bcc[i]);
            if (log.isDebugEnabled())
                log.debug("blind copying e-mail to: " + bcc[i]);
        }
        message.setRecipients(Message.RecipientType.BCC, copyTo);
    }
    message.setSubject((subject == null) ? "(no subject)" : subject);
    message.setContent(content, mimeType);
    message.setSentDate(new java.util.Date());

    // First collect all the addresses together.
    Address[] remainingAddresses = message.getAllRecipients();
    int nAddresses = remainingAddresses.length;
    boolean bFailedToSome = false;

    SendFailedException sendex = new SendFailedException("Unable to send message to some recipients");

    Transport transport = mailProvider.getTransport();

    // Try to send while there remain some potentially good addresses
    try {
        do {
            // Avoid a loop if we are stuck
            nAddresses = remainingAddresses.length;

            try {
                // Send to the list of remaining addresses, ignoring the addresses attached to the message
                transport.sendMessage(message, remainingAddresses);
            } catch (SendFailedException ex) {
                bFailedToSome = true;
                sendex.setNextException(ex);

                // Extract the remaining potentially good addresses
                remainingAddresses = ex.getValidUnsentAddresses();
            }
        } while (remainingAddresses != null && remainingAddresses.length > 0
                && remainingAddresses.length != nAddresses);

    } finally {
        transport.close();
    }

    if (bFailedToSome)
        throw sendex;
}

From source file:au.aurin.org.controller.RestController.java

public Boolean sendEmail(final String randomUUIDString, final String password, final String email,
        final List<String> lstApps, final String fullName) throws IOException {
    final String clink = classmail.getUrl() + "authchangepassword/" + randomUUIDString;

    logger.info("Starting sending Email to:" + email);
    String msg = "";

    if (!fullName.equals("")) {
        msg = msg + "Dear " + fullName + "<br>";
    }//from   www .ja v a 2s .c o  m
    Boolean lswWhatIf = false;
    if (lstApps != null) {
        //msg = msg + "You have been given access to the following applications: <br>";
        msg = msg + "<br>You have been given access to the following applications: <br>";
        for (final String st : lstApps) {
            if (st.toLowerCase().contains("whatif") || st.toLowerCase().contains("what if")) {

                lswWhatIf = true;
            }
            msg = "<br>" + msg + st + "<br>";
        }

    }

    msg = msg + "<br>Your current password is : " + password
            + " <br> To customise the password please change it using link below: <br> <a href='" + clink
            + "'> change password </a><br><br>After changing your password you can log in to the applications using your email and password. ";

    final String subject = "AURIN Workbench Access";

    final String from = classmail.getFrom();
    final String to = email;

    if (lswWhatIf == true) {
        msg = msg
                + "<br><br>If you require further support to establish a project within Online WhatIf please email your request to support@aurin.org.au";
        msg = msg + "<br>For other related requests please contact one of the members of the project team.";
        msg = msg + "<br><br>Kind Regards,";
        msg = msg + "<br>The Online WhatIf team<br>";
        msg = msg
                + "<br><strong>Prof Christopher Pettit</strong>&nbsp;&nbsp;&nbsp;&nbsp;Online WhatIf Project Director, City Futures (c.pettit@unsw.edu.au)";
        msg = msg
                + "<br><strong>Claudia Pelizaro</strong>&nbsp;&nbsp;&nbsp;&nbsp;Online WhatIf Project Manager, AURIN (claudia.pelizaro@unimelb.edu.au)";
        msg = msg
                + "<br><strong>Andrew Dingjan</strong>&nbsp;&nbsp;&nbsp;&nbsp;Director, AURIN (andrew.dingjan@unimelb.edu.au)";
        msg = msg
                + "<br><strong>Serryn Eagleson</strong>&nbsp;&nbsp;&nbsp;&nbsp;Manager Data and Business Analytics (serrynle@unimelb.edu.au)";

    } else {
        msg = msg + "<br><br>Kind Regards,";
        msg = msg + "<br>The AURIN Workbench team";
    }

    try {
        final Message message = new MimeMessage(getSession());

        message.addRecipient(RecipientType.TO, new InternetAddress(to));
        message.addFrom(new InternetAddress[] { new InternetAddress(from) });

        message.setSubject(subject);
        message.setContent(msg, "text/html");

        //////////////////////////////////
        final MimeMultipart multipart = new MimeMultipart("related");
        final BodyPart messageBodyPart = new MimeBodyPart();
        //final String htmlText = "<H1>Hello</H1><img src=\"cid:image\">";

        msg = msg + "<br><br><img src=\"cid:AbcXyz123\" />";
        //msg = msg + "<img src=\"cid:image\">";
        messageBodyPart.setContent(msg, "text/html");
        // add it
        multipart.addBodyPart(messageBodyPart);

        /////// second part (the image)
        //      messageBodyPart = new MimeBodyPart();
        final URL peopleresource = getClass().getResource("/logo.jpg");
        logger.info(peopleresource.getPath());
        //            final DataSource fds = new FileDataSource(
        //                peopleresource.getPath());
        //
        //      messageBodyPart.setDataHandler(new DataHandler(fds));
        //      messageBodyPart.setHeader("Content-ID", "<image>");
        //      // add image to the multipart
        //      //multipart.addBodyPart(messageBodyPart);

        ///////////
        final MimeBodyPart imagePart = new MimeBodyPart();
        imagePart.attachFile(peopleresource.getPath());
        //      final String cid = "1";
        //      imagePart.setContentID("<" + cid + ">");
        imagePart.setHeader("Content-ID", "AbcXyz123");
        imagePart.setDisposition(MimeBodyPart.INLINE);
        multipart.addBodyPart(imagePart);

        // put everything together
        message.setContent(multipart);
        ////////////////////////////////

        Transport.send(message);
        logger.info("Email sent to:" + email);
    } catch (final Exception mex) {
        logger.info(mex.toString());
        return false;
    }

    return true;
}