/*
Email constructor. Requires a template path to be provided, and a valid engine
must be specified in the options. See Readme.md for explanation
167196
function Email (template, options) {
	debug('email %s', template);

	options = options || {};

	if (!template) {
		throw new Error('You must provide an email template');
	}

	// init extension and engine
	// options.ext is supported for backwards compatibility with keystone.Email
	this.ext = path.extname(template) || options.ext;
	var engine = options.engine;
	if (!this.ext && !engine) {
		throw new Error('You must provide options.engine or include the extension in your template path');
	} else if (!this.ext && typeof engine === 'function') {
		throw new Error('You must include the extension in your template path when options.engine is a function');
	} else if (!this.ext) {
		this.ext = '.' + engine;
	} else if (!engine) {
		engine = this.ext.substr(1);
	}
	this.engine = getEngine(engine);
	if (typeof this.engine !== 'function') {
		throw new Error('Invalid engine (' + engine + ')');
	}
	// this corrects for if options.ext is passed in without the `.`
	if (this.ext[0] !== '.') {
		this.ext = '.' + this.ext;
	}

	// init template
	this.root = options.root || process.cwd();
	this.template = this.resolve(template);
	if (!isFile(this.template)) {
		throw new Error('Invalid template (' + template + '), could not find file "' + this.template + '"');
	}

	// init transport
	if (options.transport) {
		this.transport = getTransport(options.transport);
	}

	// stash options without consumed properties, this.send() uses it as defaults
	this.options = assign({}, options);
	delete this.options.engine;
	delete this.options.ext;
	delete this.options.root;
	delete this.options.transport;
}
429539
public String getUrl(String email) {
        if (email == null) {
            throw new IllegalArgumentException("Email can't be null.");
        }

        String emailHash = DigestUtils.md5Hex(email.trim().toLowerCase());

        boolean firstParameter = true;
        // StringBuilder standard capacity is 16 characters while the minimum
        // url is 63 characters long. The maximum length without
        // customDefaultImage
        // is 91.
        StringBuilder builder = new StringBuilder(91)
                .append(https ? HTTPS_URL : URL)
                .append(emailHash)
                .append(FILE_TYPE_EXTENSION);

        if (size != DEFAULT_SIZE) {
            addParameter(builder, "s", Integer.toString(size), firstParameter);
            firstParameter = false;
        }
        if (forceDefault) {
            addParameter(builder, "f", "y", firstParameter);
            firstParameter = false;
        }
        if (rating != DEFAULT_RATING) {
            addParameter(builder, "r", rating.getKey(), firstParameter);
            firstParameter = false;
        }
        if (customDefaultImage != null) {
            addParameter(builder, "d", customDefaultImage, firstParameter);
        } else if (standardDefaultImage != null) {
            addParameter(builder, "d", standardDefaultImage.getKey(), firstParameter);
        }

        return builder.toString();
    }
1329944
def create_user(server_context, email, container_path=None, send_email=False):
    
    url = server_context.build_url(security_controller, 'createNewUser.api', container_path)
    payload = {
        'email': email,
        'sendEmail': send_email
    }

    return server_context.make_request(url, payload)
558595
function TemplateFile(path) {

    this._buffer = FS.readFileSync(path, {"encoding": "utf8"});
    if (!this._buffer || this._buffer.length === 0) {
        throw new Error("Could not read " + path);
    }
}
160444
function createCheckEmail(fieldDefinition, fieldName) {
  const severity = propertyHelper.getSeverity(fieldDefinition);

  // return getIteratorFunction: function (fieldName, defaultValue, checkProperties, checkFunction, getErrorFunction,
  // 	getValueIfErrorFunction, getValueIfOkFunction) {

  let errorInfo = {
    severity: severity,
    errorCode: 'NOT_EMAIL'
  };

  return functionHelper.getParserCheck(errorInfo, getEmailIfValid, fieldName, undefined);

}
466926
public void checkEmail(String email) throws CmsIllegalArgumentException {

        if (CmsStringUtil.isNotEmpty(email)) {
            email = email.trim();
            email = email.toLowerCase(Locale.ROOT);
        }
        if (!CmsStringUtil.validateRegex(email, EMAIL_REGEX, false)) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_EMAIL_VALIDATION_1, email));
        }
    }
323608
def send_email_template(slug, base_url=None, context=None, user=None,
                       to=None, cc=None, bcc=None, attachments=None, headers=None, connection=None, fail_silently=False):
    
    email_template = EmailTemplate.objects.get_for_slug(slug)

    email = email_template.get_email_message(
        base_url, context, user,
        to=to, cc=cc, bcc=bcc,
        attachments=attachments, headers=headers, connection=connection
    )

    return email.send(fail_silently=fail_silently)
946525
public Configuration from(String name, String email) {
        return from(MailBuilder.email(name, email));
    }
1154800
public MailBuilder cc(String name, String email) {
        return param("cc", email(name, email));
    }
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;
        }

    }
408839
function Email (options) {
  this.action = options.action || SEND_EMAIL_ACTION;
  this.key = options.key;
  this.secret = options.secret;
  this.amazon = options.amazon;
  this.from = options.from;
  this.subject = options.subject;
  this.message = options.message;
  this.altText = options.altText;
  this.rawMessage = options.rawMessage;
  this.configurationSet = options.configurationSet;
  this.messageTags = options.messageTags;
  this.extractRecipient(options, 'to');
  this.extractRecipient(options, 'cc');
  this.extractRecipient(options, 'bcc');
  this.extractRecipient(options, 'replyTo');
}
674176
public static String getEmailDomain(final String email) {
    if (email == null || email.isEmpty()) {
      return null;
    }

    final int atSignIndex = email.indexOf('@');
    if (atSignIndex != -1) {
      return email.substring(atSignIndex + 1);
    }

    return null;
  }
611964
public static Mail buildDynamicTemplate() throws IOException {
    Mail mail = new Mail();

    Email fromEmail = new Email();
    fromEmail.setName("Example User");
    fromEmail.setEmail("test@example.com");
    mail.setFrom(fromEmail);

    mail.setTemplateId("d-c6dcf1f72bdd4beeb15a9aa6c72fcd2c");

    Personalization personalization = new Personalization();
    personalization.addDynamicTemplateData("name", "Example User");
    personalization.addDynamicTemplateData("city", "Denver");
    personalization.addTo(new Email("test@example.com"));
    mail.addPersonalization(personalization);
    
    return mail;
  }
946666
public MailBuilder from(String name, String email) {
        return param("from", email(name, email));
    }
971122
function ListenToEmail(params) {
        RED.nodes.createNode(this, params);
        this.name = params.name;
        this.waitfor = params.waitfor;
        let node = this;
        this.on('input', function(msg) {
            if (msg.error) {
                // FIXME: Add error handling here
            } else {
                node.log('ListenToEmail');
                // node.log(JSON.stringify(params));
                retryParams = params;
                emailInNode(node, params, msg);
            }
        });
        this.on('close', function() {
            if (node.interval_id != null) {
                clearInterval(node.interval_id);
            }
            if (imap) {
                imap.destroy();
            }
        });

        // Repeat interval
        if (!isNaN(params.repeat) && params.repeat > 0) {
            node.interval_id = setInterval(function() {
                if (retryParams) {
                    console.log('>Calling node emit input');
                    node.emit('input', retryParams);
                }
            }, params.repeat * 1000);
        }
    }
770357
@NonNull
    public EmailIntentBuilder cc(@NonNull Collection<String> cc) {
        checkNotNull(cc);
        for (String email : cc) {
            checkEmail(email);
        }
        this.cc.addAll(cc);

        return this;
    }
614756
public static void configureMail(CmsMailHost host, Email mail) {

        // set the host to the default mail host
        mail.setHostName(host.getHostname());
        mail.setSmtpPort(host.getPort());

        // check if username and password are provided
        String userName = host.getUsername();
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(userName)) {
            // authentication needed, set user name and password
            mail.setAuthentication(userName, host.getPassword());
        }
        String security = host.getSecurity() != null ? host.getSecurity().trim() : null;
        if (SECURITY_SSL.equalsIgnoreCase(security)) {
            mail.setSslSmtpPort("" + host.getPort());
            mail.setSSLOnConnect(true);
        } else if (SECURITY_STARTTLS.equalsIgnoreCase(security)) {
            mail.setStartTLSEnabled(true);
        }

        try {
            // set default mail from address
            mail.setFrom(OpenCms.getSystemInfo().getMailSettings().getMailFromDefault());
        } catch (EmailException e) {
            // default email address is not valid, log error
            LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_SENDER_ADDRESS_0), e);
        }
    }