/**
         * This Ajax sends a test email
         */
        function sendTestEmailViaAjax()
        {
            // Postman API: Get the plugin metadata
            $pluginData = apply_filters('postman_get_plugin_metadata', null);
            // get the email address of the recipient from the HTTP Request
            $email = $this->getRequestParameter('email');
            // get the name of the server from the HTTP Request
            $serverName = PostmanUtils::postmanGetServerName();
            /* translators: where %s is the domain name of the site */
            $subject = sprintf(_x('Postman SMTP Test (%s)', 'Test Email Subject', 'postman-smtp'), $serverName);
            // the plain-text content
            /* translators: where %s is the Postman plugin version number (e.g. 1.4) */
            // English - Mandarin - French - Hindi - Spanish - Portuguese - Russian - Japanese
            $message1 = sprintf('Hello! - 你好 - Bonjour! - नमस्ते - ¡Hola! - Olá - Привет! - 今日は%s%s%s - https://wordpress.org/plugins/postman-smtp/', PostmanMessage::EOL, PostmanMessage::EOL, sprintf(_x('Sent by Postman %s', 'Test Email Tagline', 'postman-smtp'), $pluginData['version']));
            // the HTML content
            $message2 = '
Content-Type: text/plain; charset = "UTF-8"
Content-Transfer-Encoding: 8bit

' . $message1 . '

Content-Type: text/html; charset = "UTF-8"
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="all">
.wporg-notification .im {
	color: #888;
} /* undo a GMail-inserted style */
</style>
</head>
<body class="wporg-notification">
	<div
		style="background: #e8f6fe; font-family: &amp; quot; Helvetica Neue&amp;quot; , Helvetica ,Arial,sans-serif; font-size: 14px; color: #666; text-align: center; margin: 0; padding: 0">

		<table border="0" cellspacing="0" cellpadding="0" bgcolor="#e8f6fe"
			style="background: #e8f6fe; width: 100%;">
			<tbody>
				<tr>
					<td>
						<table border="0" cellspacing="0" cellpadding="0" align="center"
							style="padding: 0px; width: 100%;"">
							<tbody>
								<tr>
									<td>
										<div
											style="max-width: 600px; height: 400px; margin: 0 auto; overflow: hidden;background-image:url(\'https://ps.w.org/postman-smtp/assets/email/poofytoo.png\');background-repeat: no-repeat;">
											<div style="margin:50px 0 0 300px; width:300px; font-size:2em;">Hello! - 你好 - Bonjour! - नमस्ते - ¡Hola! - Olá - Привет! - 今日は</div>' . sprintf('<div style="text-align:right;font-size: 1.4em; color:black;margin:150px 0 0 200px;">%s<br/><span style="font-size: 0.8em"><a style="color:#3f73b9" href="https://wordpress.org/plugins/postman-smtp/">https://wordpress.org/plugins/postman-smtp/</a></span></div>', sprintf(_x('Sent by Postman %s', 'Test Email Tagline', 'postman-smtp'), $pluginData['version'])) . '</div>
									</td>
								</tr>
							</tbody>
						</table> <br><span style="font-size:0.9em;color:#94c0dc;">' . __('Image source', 'postman-smtp') . ': <a style="color:#94c0dc" href="http://poofytoo.com">poofytoo.com</a> - ' . __('Used with permission', 'postman-smtp') . '</span></td>
				</tr>
			</tbody>
		</table>
</body>

</html>
				';
            // this header specifies that there are many parts (one text part, one html part)
            $header = 'Content-Type: multipart/alternative;';
            // Postman API: indicate to Postman this is just for testing
            add_filter('postman_test_email', array($this, 'test_mode'));
            // send the message
            $success = wp_mail($email, $subject, $message2, $header);
            // Postman API: remove the testing indicator
            remove_filter('postman_test_email', array($this, 'test_mode'));
            // Postman API: retrieve the result of sending this message from Postman
            $result = apply_filters('postman_wp_mail_result', null);
            // post-handling
            if ($success) {
                $this->logger->debug('Test Email delivered to server');
                // the message was sent successfully, generate an appropriate message for the user
                $statusMessage = sprintf(__('Your message was delivered (%d ms) to the SMTP server! Congratulations :)', 'postman-smtp'), $result['time']);
            } else {
                $this->logger->error('Test Email NOT delivered to server - ' . $result['exception']->getCode());
                // the message was NOT sent successfully, generate an appropriate message for the user
                $statusMessage = $result['exception']->getMessage();
            }
            $this->logger->debug('statusmessage: ' . $statusMessage);
            // compose the JSON response for the caller
            $response = array('message' => $statusMessage, 'transcript' => $result['transcript'], 'success' => $success);
            // send the JSON response
            wp_send_json($response);
        }
Esempio n. 2
0
 /**
  * Given a hostname, test if it has open ports
  *
  * @param string $hostname        	
  */
 private function talkToMailServer($connectionString)
 {
     $this->logger->trace('talkToMailServer()');
     $stream = $this->createStream($connectionString, $this->connectionTimeout);
     if ($stream) {
         $serverName = PostmanUtils::postmanGetServerName();
         @stream_set_timeout($stream, $this->readTimeout);
         // see http://php.net/manual/en/transports.inet.php#113244
         // see http://php.net/stream_socket_enable_crypto
         $result = $this->readSmtpResponse($stream);
         if ($result) {
             $this->reportedHostname = $result;
             $this->reportedHostnameDomainOnly = $this->getRegisteredDomain($this->reportedHostname);
             $this->logger->trace(sprintf('comparing %s with %s', $this->reportedHostnameDomainOnly, $this->hostnameDomainOnly));
             $this->mitm = true;
             // MITM exceptions
             if ($this->reportedHostnameDomainOnly == 'google.com' && $this->hostnameDomainOnly == 'gmail.com') {
                 $this->mitm = false;
             } elseif ($this->reportedHostnameDomainOnly == 'hotmail.com' && $this->hostnameDomainOnly == 'live.com') {
                 $this->mitm = false;
             } elseif ($this->reportedHostnameDomainOnly == $this->hostnameDomainOnly) {
                 $this->mitm = false;
             }
             $this->debug(sprintf('domain name: %s (%s)', $this->reportedHostname, $this->reportedHostnameDomainOnly));
             $this->sendSmtpCommand($stream, sprintf('EHLO %s', $serverName));
             $this->readSmtpResponse($stream);
             if ($this->checkStartTls) {
                 $this->sendSmtpCommand($stream, 'STARTTLS');
                 $this->readSmtpResponse($stream);
                 $starttlsSuccess = @stream_socket_enable_crypto($stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
                 if ($starttlsSuccess) {
                     $this->startTls = true;
                     $this->secure = true;
                     $this->sendSmtpCommand($stream, sprintf('EHLO %s', $serverName));
                     $this->readSmtpResponse($stream);
                 } else {
                     $this->error('starttls failed');
                 }
             }
             fclose($stream);
             $this->debug('return true');
             return true;
         } else {
             fclose($stream);
             $this->debug('return false');
             return false;
         }
     } else {
         return false;
     }
 }
 /**
  * This Ajax sends a test email
  */
 function sendTestEmailViaAjax()
 {
     // get the email address of the recipient from the HTTP Request
     $email = $this->getRequestParameter('email');
     // get the name of the server from the HTTP Request
     $serverName = PostmanUtils::postmanGetServerName();
     /* translators: where %s is the domain name of the site */
     $subject = sprintf(_x('Postman SMTP Test (%s)', 'Test Email Subject', 'postman-smtp'), $serverName);
     // Postman API: indicate to Postman this is just for testing
     add_filter('postman_test_email', array($this, 'test_mode'));
     // this header specifies that there are many parts (one text part, one html part)
     $header = 'Content-Type: multipart/alternative;';
     // createt the message content
     $message = $this->createMessageContent();
     // send the message
     $success = wp_mail($email, $subject, $message, $header);
     // Postman API: remove the testing indicator
     remove_filter('postman_test_email', array($this, 'test_mode'));
     // Postman API: retrieve the result of sending this message from Postman
     $result = apply_filters('postman_wp_mail_result', null);
     // post-handling
     if ($success) {
         $this->logger->debug('Test Email delivered to server');
         // the message was sent successfully, generate an appropriate message for the user
         $statusMessage = sprintf(__('Your message was delivered (%d ms) to the SMTP server! Congratulations :)', 'postman-smtp'), $result['time']);
     } else {
         $this->logger->error('Test Email NOT delivered to server - ' . $result['exception']->getCode());
         // the message was NOT sent successfully, generate an appropriate message for the user
         $statusMessage = $result['exception']->getMessage();
     }
     $this->logger->debug('statusmessage: ' . $statusMessage);
     // compose the JSON response for the caller
     $response = array('message' => $statusMessage, 'transcript' => $result['transcript'], 'success' => $success);
     // send the JSON response
     wp_send_json($response);
 }