Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.

@param setup     the setup type, such as <code>ServerSetup.IMAP</code>
@param mailProps additional mail properties.
@return the JavaMail session.
961443
public static Session getSession(final ServerSetup setup, Properties mailProps) {
        Properties props = setup.configureJavaMailSessionProperties(mailProps, false);

        log.debug("Mail session properties are {}", props);

        return Session.getInstance(props, null);
    }
145838
@Sensitive
    @Override
    public InjectionBinding<MailSessionDefinition> createInjectionBinding(@Sensitive MailSessionDefinition annotation, Class<?> instanceClass, Member member, String jndiName) throws InjectionException {
        InjectionBinding<MailSessionDefinition> injectionBinding =
                        new MailSessionDefinitionInjectionBinding(jndiName, ivNameSpaceConfig);
        injectionBinding.merge(annotation, instanceClass, null);
        return injectionBinding;
    }
925679
protected void configure(Properties properties) {
        _properties = properties;
        _recipients = properties.getProperty("mail.smtp.to").split(" *[,;] *");
        _authenticator = new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(_properties.getProperty("mail.smtp.user"), _properties.getProperty("mail.smtp.pass"));
            }
        };
    }
564594
public static void mail(String mailAddress) {
		final Desktop dsktop = getDsktop();
		try {
			dsktop.mail(URLUtil.toURI(mailAddress));
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
1327925
public void setMailDefaultCharset(String charset) throws PageException {
	checkWriteAccess();
	boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_MAIL);
	if (!hasAccess) throw new SecurityException("no access to update mail server settings");

	if (!StringUtil.isEmpty(charset)) {
	    try {
		IOUtil.checkEncoding(charset);
	    }
	    catch (IOException e) {
		throw Caster.toPageException(e);
	    }
	}

	Element mail = _getRootElement("mail");
	mail.setAttribute("default-encoding", charset);
	// config.setMailDefaultEncoding(charset);
    }
386701
boolean sendMail() {

        if(!this.isPropertiesSet()) {
            logger.debug(LOG_PREFIX + ": Required Mail Properties are not set. Attachments will not be sent");
            return false;
        }

        Properties prop = new Properties();
        prop.put("mail.smtp.auth", true);
        prop.put("mail.smtp.starttls.enable", "true");
        prop.put("mail.smtp.host", this.host);
        prop.put("mail.smtp.port", this.port);
        prop.put("mail.smtp.ssl.trust", host);

        logger.debug(LOG_PREFIX + ": Mail properties set");

        Session session = Session.getInstance(prop, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });

        logger.debug(LOG_PREFIX + ": Mail Session Created");

        try {
//			create a default mime message object
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(fromAdd));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toAdd));
            message.setSubject(subject);

//          body part for message
            MimeBodyPart mimeBodyPart = new MimeBodyPart();
            mimeBodyPart.setContent(msg, "text/html");

//          body part for attachments
            MimeBodyPart attachmentBodyPart = new MimeBodyPart();
            logger.debug(LOG_PREFIX + ": " + this.attachments.length + " attachments found");
            for (File file: this.attachments) {
                attachmentBodyPart.attachFile(file);
            }

//          create a multipart to combine them together
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(mimeBodyPart);
            multipart.addBodyPart(attachmentBodyPart);

            //now set the multipart as the content of the message
            message.setContent(multipart);

//			send the message
            Transport.send(message);

            logger.debug(LOG_PREFIX + ": MESSAGE SENT SUCCESSFULLY");

            return true;

        } catch (Exception e) {
            logger.debug(LOG_PREFIX + ": MESSAGE NOT SENT. " + e.getLocalizedMessage());
            e.printStackTrace();
            return false;
        }

    }
136661
public MimeMessage createMimeMessage(Session session) throws MessagingException {
		if (isEmpty(htmlPart) && isEmpty(textPart)) {
			throw new IllegalArgumentException("Missing email content");
		}
		final MimeMessage msg = new MimeMessage(session);
		msg.setSubject(subject);
		msg.setFrom(new InternetAddress(from));
		msg.setContent(createMultiPart());
		msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients, false));
		return msg;
	}
159536
public static SmtpRequest mail(CharSequence sender, CharSequence... mailParameters) {
        if (mailParameters == null || mailParameters.length == 0) {
            return new DefaultSmtpRequest(SmtpCommand.MAIL,
                                          sender != null ? "FROM:<" + sender + '>' : FROM_NULL_SENDER);
        } else {
            List<CharSequence> params = new ArrayList<CharSequence>(mailParameters.length + 1);
            params.add(sender != null? "FROM:<" + sender + '>' : FROM_NULL_SENDER);
            for (CharSequence param : mailParameters) {
                params.add(param);
            }
            return new DefaultSmtpRequest(SmtpCommand.MAIL, params);
        }
    }
507057
@Override
    public String send() {

        String messageID = null;
        try {
            messageID = super.send();
        } catch (EmailException e) {
            // check if original Exception is of type SendFailedException which
            // should have been thrown by javax.mail.Transport.send()
            if (e.getCause() instanceof AuthenticationFailedException) {
                CmsMailHost host = OpenCms.getSystemInfo().getMailSettings().getDefaultMailHost();
                // wrong user credentials in opencms-system.xml: mail api does not provide a message for authentication exception

                CmsRuntimeException rte = new CmsRuntimeException(
                    Messages.get().container(
                        Messages.ERR_SEND_EMAIL_AUTHENTICATE_2,
                        host.getUsername(),
                        host.getHostname()));
                rte.initCause(e);
                throw rte;

            } else {
                CmsRuntimeException rte = new CmsRuntimeException(
                    Messages.get().container(Messages.ERR_SEND_EMAIL_CONFIG_0));
                rte.initCause(e);
                throw rte;
            }
        }
        return messageID;
    }
1182269
public MimeMessage newMessage( Session session )
    throws MessagingException, EmailException
  {
    MimeMessage message = new MimeMessage( session );

    // populate the addresses and subject.
    populate(message);

    // create the multipart content.
    MimeMultipart containingMultipart = new MimeMultipart(EmailUtil.SUBTYPE_MIXED);

    // create the message multipart content.
    MimeMultipart messageMultipart = new MimeMultipart(EmailUtil.SUBTYPE_ALTERNATIVE);
    containingMultipart.addBodyPart(EmailUtil.newMultipartBodyPart(messageMultipart));

    // create the text part.
    messageMultipart.addBodyPart(EmailUtil.newTextBodyPart(getText()));

    // create the html part.
    MimeMultipart htmlMultipart = new MimeMultipart(EmailUtil.SUBTYPE_RELATED);
    htmlMultipart.addBodyPart(EmailUtil.newHtmlBodyPart(getHtml()));
    messageMultipart.addBodyPart(EmailUtil.newMultipartBodyPart(htmlMultipart));

    /*
    // iterate over the html context, creating new elements for each.
    Iterator htmlAttachmentIterator = htmlAttachmentMap.entrySet().iterator();
    while( htmlAttachmentIterator.hasNext() ) {
      Map.Entry htmlAttachmentEntry = (Map.Entry)htmlAttachmentIterator.next();
      htmlMultipart.addBodyPart(EmailUtil.newHtmlAttachmentPart((URL)htmlAttachmentEntry.getKey(), (String)htmlAttachmentPart.getValue());
    }

    // add the html multipart to the message multipart.
    messageMultipart.addBodyPart(EmailUtil.newMultipartBodyPart(htmlMultipartBodyPart));
    */
  
      
    // create the attachments.
    for( URL attachmentUrl : attachmentUrlSet ) {
      containingMultipart.addBodyPart(EmailUtil.newAttachmentBodyPart(attachmentUrl, null));
    }
    try {
      for( StringAttachment attachment : attachmentStrings ) {
        containingMultipart.addBodyPart(EmailUtil.newAttachmentBodyPart(attachment.getContent(), null, attachment.getMimeType(), attachment.getFilename()));
      }
    } catch (IOException ioe) {
      throw new MessagingException("Unable to create attachment for string.", ioe);
    }

    message.setContent(containingMultipart);

    // save the changes.
    message.saveChanges();

    // return the email.
    return message;
  }
600564
@Override
  public <X> X session(Class<X> type)
  {
    String address = services().address(type);
    
    if (address.startsWith("/")) {
      address = "session://" + address;
    }

    return sessionImpl(address + "/").as(type);
  }
1279622
@Override
	public AMQP.BasicProperties fromMessageProperties(MessageProperties source, String charset) {

		final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile);
		if (!backend.isEmpty() && filterConfiguration.shouldProcessContext(AsyncDispatch)) {
			final Map<String, String> filteredParams = filterConfiguration.filterDeniedParams(backend.copyToMap(), AsyncDispatch);
			source.getHeaders().put(TPIC_HEADER, filteredParams);
		}

		return super.fromMessageProperties(source, charset);
	}
493844
public JaversType getJaversType(Type javaType) {
        argumentIsNotNull(javaType);

        if (javaType == Object.class) {
            return OBJECT_TYPE;
        }

        return engine.computeIfAbsent(javaType, j -> typeFactory.infer(j, findPrototype(j)));
    }
108885
public HttpSessionImpl getSession(final String sessionId) {
        final SessionManager sessionManager = deployment.getSessionManager();
        Session session = sessionManager.getSession(sessionId);
        if (session != null) {
            return SecurityActions.forSession(session, this, false);
        }
        return null;
    }
1231297
@Reference(service = MailSessionRegistrar.class,
                    policy = ReferencePolicy.DYNAMIC,
                    cardinality = ReferenceCardinality.OPTIONAL,
                    target = "(component.name=com.ibm.ws.javamail.management.j2ee.MailSessionRegistrarImpl)")
    protected void setMailSessionRegistrar(ServiceReference<MailSessionRegistrar> ref) {
        mailSessionRegistrarRef.setReference(ref);
        registerJavaMailMBean();
    }
129935
@Nonnull
  public ESuccess queueMail (@Nonnull final ISMTPSettings aSMTPSettings, @Nonnull final IMutableEmailData aMailData)
  {
    return MailAPI.queueMail (aSMTPSettings, aMailData);
  }
1049123
@Nullable
  public static EmailAddress getAsEmailAddress (@Nullable final InternetAddress aInternetAddress)
  {
    return aInternetAddress == null ? null : new EmailAddress (aInternetAddress.getAddress (),
                                                               aInternetAddress.getPersonal ());
  }