http://www.nodemailer.org/
511741
function Mailer(config, middleware) {
  
  // Set middleware instance
  app[middleware] = this;
  
  // Set configuration
  this.config = protos.extend({
    default: 'sendmail'
  }, config);
  
  createTransports.call(this);
  
}
1077093
def postToNodeInBox(self, msg, frm):
        
        logger.trace("{} appending to nodeInbox {}".format(self, msg))
        self.nodeInBox.append((msg, frm))
55948
def send(self):
        
        if self.content_type.name == 'node':
            to = [self.to.user.email]
        elif self.content_type.name == 'layer':
            to = [self.to.email]
            # layer case is slightly special, mantainers need to be notified as well
            # TODO: consider making the mantainers able to switch off notifications
            for mantainer in self.to.mantainers.all().only('email'):
                to += [mantainer.email]
        else:
            to = [self.to.email]

        context = {
            'sender_name': self.from_name,
            'sender_email': self.from_email,
            'message': self.message,
            'site': settings.SITE_NAME,
            'object_type': self.content_type.name,
            'object_name': str(self.to)
        }
        message = render_to_string('mailing/inward_message.txt', context)

        email = EmailMessage(
            # subject
            _('Contact request from %(sender_name)s - %(site)s') % context,
            # message
            message,
            # from
            settings.DEFAULT_FROM_EMAIL,
            # to
            to,
            # reply-to header
            headers={'Reply-To': self.from_email}
        )

        import socket
        # try sending email
        try:
            email.send()
            self.status = 1
        # if error
        except socket.error as e:
            # log the error
            import logging
            log = logging.getLogger(__name__)
            error_msg = 'nodeshot.community.mailing.models.inward.send(): %s' % e
            log.error(error_msg)
            # set status of the instance as "error"
            self.status = -1
1214872
protected function getMailerConfigurationTreeBuilder()
    {
        $builder = new TreeBuilder();
        $node = $builder->root('mailer');
        $node
            ->children()
            ->scalarNode('company')->end()
            ->scalarNode('from_email')->end()
            ->scalarNode('from_name')->end()
            ->end();

        return $node;
    }
1019681
def mail_admins(subject, message, fail_silently=False, connection=None,
                html_message=None):
    """"""
    if not settings.ADMINS:
        return
    mail = EmailMultiAlternatives('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject),
                                  message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS],
                                  connection=connection)
    if html_message:
        mail.attach_alternative(html_message, 'text/html')
    mail.send(fail_silently=fail_silently)
1143606
function(apiKey, contactId, fromName,
        fromAddress, toAddress, ccAddresses, bccAddresses, contentType,
        subject, htmlBody, textBody, header, receivedDate, sentDate,
        emailSentType) {}
512188
private String createMailToLink(String to, String bcc, String cc,
            String subject, String body) {
        Validate.notNull(to, "You must define a to-address");
        final StringBuilder urlBuilder = new StringBuilder("mailto:");
        addEncodedValue(urlBuilder, "to", to);
        if (bcc != null || cc != null || subject != null || body != null) {
            urlBuilder.append('?');
        }
        addEncodedValue(urlBuilder, "bcc", bcc);
        addEncodedValue(urlBuilder, "cc", cc);
        addEncodedValue(urlBuilder, "subject", subject);
        if (body != null) {
            addEncodedValue(urlBuilder, "body", body.replace("$NL$", "\r\n"));
        }

        return urlBuilder.toString();
    }
665066
public void updateMailServer(int id, String hostName, String username, String password, int port, boolean tls, boolean ssl, long lifeTimeSpan, long idleTimeSpan,
	    boolean reuseConnections) throws PageException {
	checkWriteAccess();
	boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_MAIL);
	if (!hasAccess) throw new SecurityException("no access to update mail server settings");

	Element mail = _getRootElement("mail");
	if (port < 1) port = 21;

	if (hostName == null || hostName.trim().length() == 0) throw new ExpressionException("Host (SMTP) can be a empty value");
	hostName = hostName.trim();

	Element[] children = XMLConfigWebFactory.getChildren(mail, "server");

	boolean checkId = id > 0;

	// Update
	Element server = null;
	String _hostName, _username;
	for (int i = 0; i < children.length; i++) {
	    Element el = children[i];
	    if (checkId) {
		if (i + 1 == id) {
		    server = el;
		    break;
		}
	    }
	    else {
		_hostName = StringUtil.emptyIfNull(el.getAttribute("smtp"));
		_username = StringUtil.emptyIfNull(el.getAttribute("username"));
		if (_hostName.equalsIgnoreCase(hostName) && _username.equals(StringUtil.emptyIfNull(username))) {
		    server = el;
		    break;
		}
	    }
	}

	// Insert
	if (server == null) {
	    server = doc.createElement("server");
	    mail.appendChild(XMLCaster.toRawNode(server));
	}
	server.setAttribute("smtp", hostName);
	server.setAttribute("username", username);
	server.setAttribute("password", ConfigWebUtil.encrypt(password));
	server.setAttribute("port", Caster.toString(port));
	server.setAttribute("tls", Caster.toString(tls));
	server.setAttribute("ssl", Caster.toString(ssl));
	server.setAttribute("life", Caster.toString(lifeTimeSpan));
	server.setAttribute("idle", Caster.toString(idleTimeSpan));
	server.setAttribute("reuse-connection", Caster.toString(reuseConnections));

    }
1260700
def url(self):
        """"""
        return reverse('archives:thread_view',
                       args=[self.mailinglist.name,
                             self.thread.subject_token])
1369747
def api_send_mail(request, key=None, hproPk=None):
    """"""

    if not check_api_key(request, key, hproPk):
        return HttpResponseForbidden

    sender = request.POST.get('sender', settings.MAIL_SENDER)
    dests = request.POST.getlist('dests')
    subject = request.POST['subject']
    message = request.POST['message']
    html_message = request.POST.get('html_message')

    if html_message and html_message.lower() == 'false':
        html_message = False

    if 'response_id' in request.POST:
        key = hproPk + ':' + request.POST['response_id']
    else:
        key = None

    generic_send_mail(sender, dests, subject, message, key, 'PlugIt API (%s)' % (hproPk or 'StandAlone',), html_message)

    return HttpResponse(json.dumps({}), content_type="application/json")
862840
public function index()
    {
        $this->breadcrumb->onMailConfiguration();
        $memory   = app('antares.memory')->make('primary');
        $eloquent = new Fluent([
            'site_name'        => $memory->get('site.name', ''),
            'site_description' => $memory->get('site.description', ''),
            'site_registrable' => ($memory->get('site.registrable', false) ? 'yes' : 'no'),
            'mode'             => $memory->get('site.mode', 'development'),
            'email_driver'     => $memory->get('email.driver', ''),
            'email_address'    => $memory->get('email.from.address', ''),
            'email_host'       => $memory->get('email.host', ''),
            'email_port'       => $memory->get('email.port', ''),
            'email_username'   => $memory->get('email.username', ''),
            'email_password'   => $memory->get('email.password', ''),
            'email_encryption' => $memory->get('email.encryption', ''),
            'email_sendmail'   => $memory->get('email.sendmail', ''),
            'email_queue'      => ($memory->get('email.queue', false) ? 'yes' : 'no'),
            'email_key'        => $memory->get('email.key', ''),
            'email_secret'     => $memory->get('email.secret', ''),
            'email_domain'     => $memory->get('email.domain', ''),
            'email_region'     => $memory->get('email.region', ''),
        ]);
        $form     = new MailForm($eloquent);
        return compact('eloquent', 'form');
    }
704681
async def mail(
        self,
        sender: str,
        options: Iterable[str] = None,
        timeout: DefaultNumType = _default,
    ) -> SMTPResponse:
        
        await self._ehlo_or_helo_if_needed()

        if options is None:
            options = []

        options_bytes = [option.encode("ascii") for option in options]
        from_string = b"FROM:" + quote_address(sender).encode("ascii")

        async with self._command_lock:
            response = await self.execute_command(
                b"MAIL", from_string, *options_bytes, timeout=timeout
            )

        if response.code != SMTPStatus.completed:
            raise SMTPSenderRefused(response.code, response.message, sender)

        return response
104587
function init() {
	// Locate config if we dont have one {{{
	if (_.isUndefined(appConfig)) {
		appConfigLocations.forEach(function(key) {
			if (_.has(global, key)) {
				appConfig = _.get(global, key);
				return false;
			}
		});
		if (_.isUndefined(appConfig)) throw new Error('Cannot find email config in', appConfigLocations);
	}
	// }}}

	this.config = { // Reset basics
		from: appConfig.email.from,
		to: appConfig.email.to,
		subject: appConfig.email.subject || '',
		cc: appConfig.email.cc || [],
		bcc: appConfig.email.bcc || [],
	};

	// Work out mail transport {{{
	if (appConfig.email.enabled) {
		switch (appConfig.email.method) {
			case 'mailgun':
				if (
					/^https?:\/\//.test(appConfig.mailgun.domain) ||
					/mailgun/.test(appConfig.mailgun.domain)
				) throw new Error("Mailgun domain should not contain 'http(s)://' prefix or mailgun. Should resemble the domain name e.g. 'acme.com'");

				transporter = nodemailer.createTransport(nodemailerMailgun({
					auth: {
						api_key: appConfig.mailgun.apiKey,
						domain: appConfig.mailgun.domain,
					},
				}));
				break
			case 'sendmail':
				transporter = nodemailer.createTransport(nodemailerSendmail());
				break;
			default:
				next('Unknown mail transport method: ' + appConfig.email.method);
		}
	}
	// }}}

	return this;
}
255556
private Map<String, String> getEmails(Map<String, String> emails) {

		if (emails == null || emails.size() == 0) {
			return null;
		}

		Map<String, String> out = new HashMap<>();

		for (String email : emails.keySet()) {
			if (excluded(email)) {
				continue;
			}

			out.put(email, emails.get(email));
		}

		return out;
	}
603389
public static function transport(): Swift_Transport
    {
        switch (Site::getPreference('SMTP_ACTIVE')) {
            case 'sendmail':
                // Local sendmail (requires PHP proc_* functions)
                return new Swift_SendmailTransport();

            case 'external':
                // SMTP
                $smtp_host = Site::getPreference('SMTP_HOST');
                $smtp_port = (int) Site::getPreference('SMTP_PORT', '25');
                $smtp_auth = Site::getPreference('SMTP_AUTH');
                $smtp_user = Site::getPreference('SMTP_AUTH_USER');
                $smtp_pass = Site::getPreference('SMTP_AUTH_PASS');
                $smtp_encr = Site::getPreference('SMTP_SSL');

                $transport = new Swift_SmtpTransport($smtp_host, $smtp_port, $smtp_encr);

                $transport->setLocalDomain(Site::getPreference('SMTP_HELO'));

                if ($smtp_auth) {
                    $transport
                        ->setUsername($smtp_user)
                        ->setPassword($smtp_pass);
                }

                return $transport;

            default:
                // For testing
                return new Swift_NullTransport();
        }
    }
1235461
static function phpmailer($to, $to_name, $subject, $message, $html_message = false) {
    $mail = new \PHPMailer();

    $mail->IsSMTP();                                      // set mailer to use SMTP
    $mail->Host = \Openclerk\Config::get('phpmailer_host');  // specify main and backup server
    $mail->SMTPAuth = true;     // turn on SMTP authentication
    $mail->Username = \Openclerk\Config::get('phpmailer_username');  // SMTP username
    $mail->Password = \Openclerk\Config::get('phpmailer_password'); // SMTP password

    $mail->From = \Openclerk\Config::get('phpmailer_from');
    $mail->FromName = \Openclerk\Config::get('phpmailer_from_name');
    $mail->Sender = \Openclerk\Config::get('phpmailer_from');
    $mail->AddAddress($to, $to_name);
    if (\Openclerk\Config::get('phpmailer_reply_to')) {
      $mail->AddReplyTo(\Openclerk\Config::get('phpmailer_reply_to'));
    }

    if (\Openclerk\Config::get('phpmailer_bcc', false)) {
      $mail->AddBCC(\Openclerk\Config::get('phpmailer_bcc'));
    }

    $mail->Subject = $subject;
    if ($html_message) {
      $mail->Body = $html_message;
      $mail->AltBody = $message;
      $mail->IsHTML(true);
    } else {
      $mail->Body    = $message;
    }

    if(!$mail->Send()) {
      throw new MailerException("Message could not be sent: " . $mail->ErrorInfo);
    }

    return $mail->GetLastMessageID();
  }
480331
def email(anon, obj, field, val):
    
    return anon.faker.email(field=field)