Search The ForumSearch   RegisterRegister  LoginLogin

AfterLogic WebMail Lite 7

 AfterLogic Forum : AfterLogic WebMail Lite 7
Subject Topic: Having difficulty sending smtp messages Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
smallmid
Newbie
Newbie


Joined: 19 December 2011
Location: United States
Online Status: Offline
Posts: 7
Posted: 19 December 2011 at 5:24pm | IP Logged Quote smallmid

Having difficulty sending messages via smtp. I have tried multiple ports to no avail. Just am getting the "Can't send message" error. Did see an article to possibly enable php mail but after adding the code to the routine, it still didn't remedy the problem.

Open to next steps!

Thanks,

Micahel
Back to Top View smallmid's Profile Search for other posts by smallmid
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 20 December 2011 at 12:48am | IP Logged Quote Igor

In case if you're using shared hosting, it would be a good idea to check with your host if it's allowed to send mails from PHP scripts.

Also, you'll need to check the connection parameters required by your SMTP server. If it supports port 465 or 587, make sure you have OpenSSL extension enabled in your PHP configuration.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
smallmid
Newbie
Newbie


Joined: 19 December 2011
Location: United States
Online Status: Offline
Posts: 7
Posted: 20 December 2011 at 7:53am | IP Logged Quote smallmid

Thanks for the feedback. I was instructed that I should send the mail via sendmail which is located here /usr/sbin/sendmail. Is there a modification necessary to the 'class_smtp.php' file necessary use 'sendmail' ?

Thanks,

MS
Back to Top View smallmid's Profile Search for other posts by smallmid
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 20 December 2011 at 9:51am | IP Logged Quote Igor

I think WebMail cannot use sendmail directly, unless you modify the code substantially. But if you add a modification to WebMail so that mail() function of PHP is used instead of regular SMTP approach, and make sure your PHP installation is properly configured to use sendmail - that is likely to work.

Speaking of a modification - the approach described here should still work(even though it was created for earlier versions), just make sure you add those custom lines right before the following ones:

Code:
$link = null;
$result = CSmtp::Connect($link, $account);


--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
smallmid
Newbie
Newbie


Joined: 19 December 2011
Location: United States
Online Status: Offline
Posts: 7
Posted: 20 December 2011 at 11:05am | IP Logged Quote smallmid

Here is what is added.. but generated this error.

Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /usr/www/users/appname/webmail/common/class_smtp.php on line 105


----------------------------------

<?php

/*
* AfterLogic WebMail Pro PHP by AfterLogic Corp. <support@afterlogic.com>
*
* Copyright (C) 2002-2011 AfterLogic Corp. (www.afterlogic.com)
* Distributed under the terms of the license described in COPYING
*
*/

     defined('WM_ROOTPATH') || define('WM_ROOTPATH', (dirname(__FILE__).'/../'));

     require_once(WM_ROOTPATH.'common/inc_constants.php');
     require_once(WM_ROOTPATH.'common/class_webmailmessages.php');

     define('USE_STARTTLS', true);

     /**
      * @static
      */
     class CSmtp
     {
          /**
           * @param CAccount $account
           * @param WebMailMessage $message
           * @param string $from
           * @param string $to
           * @return bool
           */
     
     
          function SendMail($account, $message, $from, $to)
          {
               
                              
               $bIsDemo = false;
               CApi::Plugin()->RunHook('plugin-is-demo-account', array(&$account, &$bIsDemo));
               
                                 &n bsp;      
               
               if ($bIsDemo)
               {
                    $allRcpt = $message->GetAllRecipients();
                    if ($allRcpt && 0 < $allRcpt->Count())
                    {
                         $bSuccessRec = true;
                         foreach (array_keys($allRcpt->Instance()) as $key)
                         {
                              $oEmail = $allRcpt->Get($key);
                              if ($bSuccessRec && $oEmail)
                              {
                                 &n bsp; $aEmailParts = explode('@', $oEmail->Email, 2);
                                 &n bsp; if ($aEmailParts && isset($aEmailParts[1]) && 'afterlogic.com' === strtolower($aEmailParts[1]))
                                 &n bsp; {
                                 &n bsp;      continue;
                                 &n bsp; }
                              }
                              
                              $bSuccessRec = false;
                         }
                         
                         if (!$bSuccessRec)
                         {
                              setGlobalError('For security reasons, this demo allows sending to '.$account->Email.' address only.');
                              return false;
                         }
                    }
                    else
                    {
                         setGlobalError('Internal error');
                         return false;
                    }
               }
               
               if ($from === null)
               {
                    $fromAddr = $message->GetFrom();
                    $from = $fromAddr->Email;
               }

               if ($to === null)
               {
                    $to = $message->GetAllRecipientsEmailsAsString();
               }
               
               
               /*------------[ Custom Code so that sendmail will work ]---------- */
               $msg = $message->TryToGetOriginalMailMessage();
               $arr = explode("\r\n\r\n", $msg, 2);
               $body = $arr[1];
               $head = explode("\r\n",$arr[0]);
               $hdrs=''; $hdr_to=''; $hdr_subj=''; $head_key='';
               foreach($head as $key => $value)
               {
                   $head_val=$value;
                   if (($epos=strpos($value,':'))!==false)
                   {
                       $head_key = substr($value,0,$epos); $head_val=substr($value,2+$epos);
                   }
                   if (($head_key)=='To') $hdr_to.=$head_val."\r\n";
                   elseif (($head_key)=='Subject') $hdr_subj.=$head_val."\r\n";
                   else $hdrs.=$value."\r\n";
               }
               if (($hdr_bcc=($message->Headers->GetHeaderValueByName("BCC")))!="") $hdrs.="Bcc: $hdr_bcc\r\n";
               return (mail($hdr_to, $hdr_subj, $body, $hdrs));
               /*------------[/ Custom Code so that sendmail will work ]---------- */
                              
               
               $link = null;
               $result = CSmtp::Connect($link, $account);
               if ($result)
               {
                    $result = CSmtp::Send($link, $account, $message, $from, $to);
                    if ($result)
                    {
                         $result = CSmtp::Disconnect($link);
                    }
               }
               else
               {
                    setGlobalError(ErrorSMTPConnect);
               }
               
               return $result;
          }
          
          
          

          
          
          
          
          
          
          
          
          
          /**
           * @access private
           * @param resource $link
           * @param CAccount $account
           * @return bool
           */
          function Connect(&$link, &$account)
          {
               $outHost = $account->OutgoingMailServer;
               
               $errno = $errstr = null;
               $out = '';
               
               if ($account->OutgoingMailUseSSL)
               {
                    $outHost = 'ssl://'.$outHost;
               }

               $sConnectTimeout = CApi::GetConf('socket.connect-timeout', 5);
               $sFgetTimeout = CApi::GetConf('socket.get-timeout', 5);

               CApi::Plugin()->RunHook('webmail-smtp-update-socket-timeouts',
                    array(&$sConnectTimeout, &$sFgetTimeout));

               CApi::Log('[SMTP] Connecting to server '. $outHost.' on port '.$account->OutgoingMailPort);
               $link = @fsockopen($outHost, $account->OutgoingMailPort, $errno, $errstr, $sConnectTimeout);
               if(!$link)
               {
                    setGlobalError('[SMTP] Error: '.$errstr);
                    CApi::Log(getGlobalError(), ELogLevel::Error);
                    return false;
               }
               else
               {
                    @socket_set_timeout($link, $sFgetTimeout);
                    return CSmtp::IsSuccess($link, $out);
               }
          }
          
          /**
           * @access private
           * @param resource $link
           * @return bool
           */
          function Disconnect(&$link)
          {
               $out = '';
               return CSmtp::ExecuteCommand($link, 'QUIT', $out);
          }

          /**
           * @access private
           * @param resource $link
           * @return bool
           */
          function StartTLS(&$link)
          {
               $out = '';
               return CSmtp::ExecuteCommand($link, 'STARTTLS', $out);
          }
          
          /**
           * @access private
           * @param resource $link
           * @param CAccount $account
           * @param WebMailMessage $message
           * @param string $from
           * @param string $to
           * @return bool
           */
          function Send(&$link, &$account, &$message, $from, $to)
          {
               $ehloMsg = trim(EmailAddress::GetDomainFromEmail($account->Email));
               $ehloMsg = strlen($ehloMsg) > 0 ? $ehloMsg : trim(EmailAddress::GetDomainFromEmail($account->IncomingMailLogin));

               $out = '';
               $result = CSmtp::ExecuteCommand($link, 'EHLO '.$ehloMsg, $out);
               if (!$result)
               {
                    $result = CSmtp::ExecuteCommand($link, 'HELO '.$ehloMsg, $out);
               }

               if (587 === $account->OutgoingMailPort)
               {
                    $capa = CSmtp::ParseEhlo($out);
                    if ($result && in_array('STARTTLS', $capa) && USE_STARTTLS && function_exists('stream_socket_enable_crypto') && CSmtp::StartTLS($link))
                    {
                         @stream_socket_enable_crypto($link, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);

                         $result = CSmtp::ExecuteCommand($link, 'EHLO '.$ehloMsg, $out);
                         if (!$result)
                         {
                              $result = CSmtp::ExecuteCommand($link, 'HELO '.$ehloMsg, $out);
                         }
                    }
               }

               if ($result && ESMTPAuthType::NoAuth !== $account->OutgoingMailAuth)
               {
                    $result = CSmtp::ExecuteCommand($link, 'AUTH LOGIN', $out);
                    
                    $sOutgoingMailLogin = $account->OutgoingMailLogin;
                    $mailOutLogin = !empty($sOutgoingMailLogin) ? $sOutgoingMailLogin : $account->IncomingMailLogin;
                    
                    $sOutgoingMailPassword = $account->OutgoingMailPassword;
                    $mailOutPassword = !empty($sOutgoingMailPassword) ?     $sOutgoingMailPassword : $account->IncomingMailPassword;

                    CApi::Plugin()->RunHook('webmail-smtp-change-auth-login',
                         array(&$mailOutLogin, &$mailOutPassword));

                    if ($result)
                    {
                         CApi::Log('[SMTP] Sending encoded login');
                         $result = CSmtp::ExecuteCommand($link, base64_encode($mailOutLogin), $out);
                    }

                    if ($result)
                    {
                         CApi::Log('[SMTP] Sending encoded password');
                         $result = CSmtp::ExecuteCommand($link, base64_encode($mailOutPassword), $out);
                    }
               }
               
               if ($result)
               {
                    $result = CSmtp::ExecuteCommand($link, 'MAIL FROM:<'.$from.'>', $out);
               }
               else
               {
                    setGlobalError(ErrorSMTPAuth);
               }
               
               if ($result)
               {
                    $toArray = explode(',', $to);
                    foreach ($toArray as $recipient)
                    {
                         $recipient = trim($recipient);
                         $result = CSmtp::ExecuteCommand($link, 'RCPT TO:<'.$recipient.'>', $out);
                         if (!$result)
                         {
                              break;
                         }
                    }
               }
               
               if ($result)
               {
                    $result = CSmtp::ExecuteCommand($link, 'DATA', $out);
               }
               
               if ($result)
               {
                    $result = CSmtp::ExecuteCommand($link, str_replace(CRLF.'.', CRLF.'..', $message->TryToGetOriginalMailMessage()).CRLF.'.', $out);
               }

               if ($result)
               {
                    CApi::LogEvent('User Send message', $account);
               }
               
               CSmtp::resetTimeOut(true);
               return $result;
          }


          function ParseEhlo($str)
          {
               $return = array();
               $arrayOut = explode("\n", $str);
               array_shift($arrayOut);
               if (is_array($arrayOut))
               {
                    foreach ($arrayOut as $line)
                    {
                         $parts = explode('-', trim($line), 2);
                         if (count($parts) == 2 && $parts[0] == '250')
                         {
                              $return[] = strtoupper(trim($parts[1]));
                         }
                    }
               }
               return $return;
          }

          /**
           * @access private
           * @param resource $link
           * @param string $command
           * @return bool
           */
          function ExecuteCommand(&$link, $command, &$out, $isLog = true)
          {
               $command = str_replace("\n", "\r\n", str_replace("\r", '', $command));
               if ($isLog)
               {
                    CApi::Log('[SMTP] >>: '.$command);
               }
               
               CSmtp::resetTimeOut();
               @fputs($link, $command.CRLF);
               return CSmtp::IsSuccess($link, $out);
          }
          
          /**
           * @access private
           * @param resource $link
           * @return bool
           */
          function IsSuccess(&$link, &$out, $isLog = true)
          {
               $out = '';
               $line = '';
               $result = true;
               do
               {
                    $line = @fgets($link, 1024);
                    if ($isLog)
                    {
                         CApi::Log('[SMTP] <<: '.trim($line));
                    }
                    if ($line === false)
                    {
                         $result = false;
                         setGlobalError('[SMTP] Error: IsSuccess fgets error');
                         break;
                    }
                    else
                    {
                         $out .= $line;
                         $line = str_replace("\r", '', str_replace("\n", '', str_replace(CRLF, '', $line)));
                         if (substr($line, 0, 1) != '2' && substr($line, 0, 1) != '3')
                         {
                              $result = false;
                              $error = '[SMTP] Error <<: ' . $line;
                              setGlobalError($erro r);
                              //setGlobalError(sub str($line, 3));
                              break;
                         }
                    }
               
               } while (substr($line, 3, 1) == '-');
               
               if (!$result && $isLog)
               {
                    CApi::Log(getGlobalError(), ELogLevel::Error);
               }
               
               return $result;
          }
          
          /**
           * @param bool $_force
           */
          function resetTimeOut($_force = false)
          {
               static $_staticTime = null;
               
               $_time = time();
               if ($_staticTime < $_time - RESET_TIME_LIMIT_RUN || $_force)
               {
                    @set_time_limit(RESET_TIME_LIMIT);
                    $_staticTime = $_time;
               }
          }
     }
Back to Top View smallmid's Profile Search for other posts by smallmid
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 21 December 2011 at 12:38am | IP Logged Quote Igor

Try debugging it to see what parameters are actually used in mail() function call, and do they look OK to you; maybe, something else is causing this.

By the way, I have checked mail() modification to work with 6.2 version, not sure if it works for 6.3 though.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
smallmid
Newbie
Newbie


Joined: 19 December 2011
Location: United States
Online Status: Offline
Posts: 7
Posted: 21 December 2011 at 6:23am | IP Logged Quote smallmid

Okay..... might be a bit limited on the debugging route. Can you send the link to the 6.2 version. I wouldn't mind using that one.
Back to Top View smallmid's Profile Search for other posts by smallmid
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 22 December 2011 at 12:46am | IP Logged Quote Igor

Sure, you can get it here.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
smallmid
Newbie
Newbie


Joined: 19 December 2011
Location: United States
Online Status: Offline
Posts: 7
Posted: 22 December 2011 at 8:26am | IP Logged Quote smallmid

Thanks much. Okay hopefully this is the final question. The article says to put the modification at the beginning of the function but you said to put it before here:

$link = null;
$result = CSmtp::Connect($link, $account);

Which one is correct. If it is easier, feel free to send the file that was tested and works for you that your mentioned above.

Thanks much

Back to Top View smallmid's Profile Search for other posts by smallmid
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 23 December 2011 at 12:12am | IP Logged Quote Igor

Quote:
The article says to put the modification at the beginning of the function


As I mentioned previously, the article was created for an older version of WebMail. In version 6.2, you'll need to place the modification before those two lines.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
smallmid
Newbie
Newbie


Joined: 19 December 2011
Location: United States
Online Status: Offline
Posts: 7
Posted: 06 January 2012 at 1:05pm | IP Logged Quote smallmid

Getting closer but still having a bit of errors.

Here is contents of the modified file which is still throwing errors.
-----------------------------------------------------------------------

<?php

/*
* AfterLogic WebMail Pro PHP by AfterLogic Corp. <support@afterlogic.com>
*
* Copyright (C) 2002-2011 AfterLogic Corp. (www.afterlogic.com)
* Distributed under the terms of the license described in COPYING
*
*/

     defined('WM_ROOTPATH') || define('WM_ROOTPATH', (dirname(__FILE__).'/../'));

     require_once(WM_ROOTPATH.'common/inc_constants.php');
     require_once(WM_ROOTPATH.'common/class_webmailmessages.php');

     define('USE_STARTTLS', true);

     /**
      * @static
      */
     class CSmtp
     {
          /**
           * @param CAccount $account
           * @param WebMailMessage $message
           * @param string $from
           * @param string $to
           * @return bool
           */
          function SendMail($account, $message, $from, $to)
          {
               $bIsDemo = false;
               CApi::Plugin()->RunHook('plugin-is-demo-account', array(&$account, &$bIsDemo));
               
               if ($bIsDemo)
               {
                    $allRcpt = $message->GetAllRecipients();
                    if ($allRcpt && 0 < $allRcpt->Count())
                    {
                         $bSuccessRec = true;
                         foreach (array_keys($allRcpt->Instance()) as $key)
                         {
                              $oEmail = $allRcpt->Get($key);
                              if ($bSuccessRec && $oEmail)
                              {
                                 &n bsp; $aEmailParts = explode('@', $oEmail->Email, 2);
                                 &n bsp; if ($aEmailParts && isset($aEmailParts[1]) && 'afterlogic.com' === strtolower($aEmailParts[1]))
                                 &n bsp; {
                                 &n bsp;      continue;
                                 &n bsp; }
                              }
                              
                              $bSuccessRec = false;
                         }
                         
                         if (!$bSuccessRec)
                         {
                              setGlobalError('For security reasons, this demo allows sending to '.$account->Email.' address only.');
                              return false;
                         }
                    }
                    else
                    {
                         setGlobalError('Internal error');
                         return false;
                    }
               }
               
               if ($from === null)
               {
                    $fromAddr = $message->GetFrom();
                    $from = $fromAddr->Email;
               }

               if ($to === null)
               {
                    $to = $message->GetAllRecipientsEmailsAsString();
               }
               
               
               
               $msg = $message->TryToGetOriginalMailMessage();
               $arr = explode("\r\n\r\n", $msg, 2);
               $body = $arr[1];
               $head = explode("\r\n",$arr[0]);
               $hdrs=''; $hdr_to=''; $hdr_subj=''; $head_key='';
               foreach($head as $key => $value)
               {
                   $head_val=$value;
                   if (($epos=strpos($value,':'))!==false)
                   {
                       $head_key = substr($value,0,$epos); $head_val=substr($value,2+$epos);
                   }
                   if (($head_key)=='To') $hdr_to.=$head_val."\r\n";
                   elseif (($head_key)=='Subject') $hdr_subj.=$head_val."\r\n";
                   else $hdrs.=$value."\r\n";
               }
               if (($hdr_bcc=($message->Headers->GetHeaderValueByName("BCC")))!="") $hdrs.="Bcc: $hdr_bcc\r\n";
               return (mail($hdr_to, $hdr_subj, $body, $hdrs));
               
                              
               
               $link = null;
               $result = CSmtp::Connect($link, $account);
               if ($result)
               {
                    $result = CSmtp::Send($link, $account, $message, $from, $to);
                    if ($result)
                    {
                         $result = CSmtp::Disconnect($link);
                    }
               }
               else
               {
                    setGlobalError(ErrorSMTPConnect);
               }
               
               return $result;
          }
          
          
          /**
           * @access private
           * @param resource $link
           * @param CAccount $account
           * @return bool
           */
          function Connect(&$link, &$account)
          {
               $outHost = $account->OutgoingMailServer;
               
               $errno = $errstr = null;
               $out = '';
               
               if ($account->OutgoingMailUseSSL)
               {
                    $outHost = 'ssl://'.$outHost;
               }

               $sConnectTimeout = CApi::GetConf('socket.connect-timeout', 5);
               $sFgetTimeout = CApi::GetConf('socket.get-timeout', 5);

               CApi::Plugin()->RunHook('webmail-smtp-update-socket-timeouts',
                    array(&$sConnectTimeout, &$sFgetTimeout));

               CApi::Log('[SMTP] Connecting to server '. $outHost.' on port '.$account->OutgoingMailPort);
               $link = @fsockopen($outHost, $account->OutgoingMailPort, $errno, $errstr, $sConnectTimeout);
               if(!$link)
               {
                    setGlobalError('[SMTP] Error: '.$errstr);
                    CApi::Log(getGlobalError(), ELogLevel::Error);
                    return false;
               }
               else
               {
                    @socket_set_timeout($link, $sFgetTimeout);
                    return CSmtp::IsSuccess($link, $out);
               }
          }
          
          /**
           * @access private
           * @param resource $link
           * @return bool
           */
          function Disconnect(&$link)
          {
               $out = '';
               return CSmtp::ExecuteCommand($link, 'QUIT', $out);
          }

          /**
           * @access private
           * @param resource $link
           * @return bool
           */
          function StartTLS(&$link)
          {
               $out = '';
               return CSmtp::ExecuteCommand($link, 'STARTTLS', $out);
          }
          
          /**
           * @access private
           * @param resource $link
           * @param CAccount $account
           * @param WebMailMessage $message
           * @param string $from
           * @param string $to
           * @return bool
           */
          function Send(&$link, &$account, &$message, $from, $to)
          {
               $ehloMsg = trim(EmailAddress::GetDomainFromEmail($account->Email));
               $ehloMsg = strlen($ehloMsg) > 0 ? $ehloMsg : trim(EmailAddress::GetDomainFromEmail($account->IncomingMailLogin));

               $out = '';
               $result = CSmtp::ExecuteCommand($link, 'EHLO '.$ehloMsg, $out);
               if (!$result)
               {
                    $result = CSmtp::ExecuteCommand($link, 'HELO '.$ehloMsg, $out);
               }

               if (587 === $account->OutgoingMailPort)
               {
                    $capa = CSmtp::ParseEhlo($out);
                    if ($result && in_array('STARTTLS', $capa) && USE_STARTTLS && function_exists('stream_socket_enable_crypto') && CSmtp::StartTLS($link))
                    {
                         @stream_socket_enable_crypto($link, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);

                         $result = CSmtp::ExecuteCommand($link, 'EHLO '.$ehloMsg, $out);
                         if (!$result)
                         {
                              $result = CSmtp::ExecuteCommand($link, 'HELO '.$ehloMsg, $out);
                         }
                    }
               }

               if ($result && ESMTPAuthType::NoAuth !== $account->OutgoingMailAuth)
               {
                    $result = CSmtp::ExecuteCommand($link, 'AUTH LOGIN', $out);
                    
                    $sOutgoingMailLogin = $account->OutgoingMailLogin;
                    $mailOutLogin = !empty($sOutgoingMailLogin) ? $sOutgoingMailLogin : $account->IncomingMailLogin;
                    
                    $sOutgoingMailPassword = $account->OutgoingMailPassword;
                    $mailOutPassword = !empty($sOutgoingMailPassword) ?     $sOutgoingMailPassword : $account->IncomingMailPassword;

                    CApi::Plugin()->RunHook('webmail-smtp-change-auth-login',
                         array(&$mailOutLogin, &$mailOutPassword));

                    if ($result)
                    {
                         CApi::Log('[SMTP] Sending encoded login');
                         $result = CSmtp::ExecuteCommand($link, base64_encode($mailOutLogin), $out);
                    }

                    if ($result)
                    {
                         CApi::Log('[SMTP] Sending encoded password');
                         $result = CSmtp::ExecuteCommand($link, base64_encode($mailOutPassword), $out);
                    }
               }
               
               if ($result)
               {
                    $result = CSmtp::ExecuteCommand($link, 'MAIL FROM:<'.$from.'>', $out);
               }
               else
               {
                    setGlobalError(ErrorSMTPAuth);
               }
               
               if ($result)
               {
                    $toArray = explode(',', $to);
                    foreach ($toArray as $recipient)
                    {
                         $recipient = trim($recipient);
                         $result = CSmtp::ExecuteCommand($link, 'RCPT TO:<'.$recipient.'>', $out);
                         if (!$result)
                         {
                              break;
                         }
                    }
               }
               
               if ($result)
               {
                    $result = CSmtp::ExecuteCommand($link, 'DATA', $out);
               }
               
               if ($result)
               {
                    $result = CSmtp::ExecuteCommand($link, str_replace(CRLF.'.', CRLF.'..', $message->TryToGetOriginalMailMessage()).CRLF.'.', $out);
               }

               if ($result)
               {
                    CApi::LogEvent('User Send message', $account);
               }
               
               CSmtp::resetTimeOut(true);
               return $result;
          }


          function ParseEhlo($str)
          {
               $return = array();
               $arrayOut = explode("\n", $str);
               array_shift($arrayOut);
               if (is_array($arrayOut))
               {
                    foreach ($arrayOut as $line)
                    {
                         $parts = explode('-', trim($line), 2);
                         if (count($parts) == 2 && $parts[0] == '250')
                         {
                              $return[] = strtoupper(trim($parts[1]));
                         }
                    }
               }
               return $return;
          }

          /**
           * @access private
           * @param resource $link
           * @param string $command
           * @return bool
           */
          function ExecuteCommand(&$link, $command, &$out, $isLog = true)
          {
               $command = str_replace("\n", "\r\n", str_replace("\r", '', $command));
               if ($isLog)
               {
                    CApi::Log('[SMTP] >>: '.$command);
               }
               
               CSmtp::resetTimeOut();
               @fputs($link, $command.CRLF);
               return CSmtp::IsSuccess($link, $out);
          }
          
          /**
           * @access private
           * @param resource $link
           * @return bool
           */
          function IsSuccess(&$link, &$out, $isLog = true)
          {
               $out = '';
               $line = '';
               $result = true;
               do
               {
                    $line = @fgets($link, 1024);
                    if ($isLog)
                    {
                         CApi::Log('[SMTP] <<: '.trim($line));
                    }
                    if ($line === false)
                    {
                         $result = false;
                         setGlobalError('[SMTP] Error: IsSuccess fgets error');
                         break;
                    }
                    else
                    {
                         $out .= $line;
                         $line = str_replace("\r", '', str_replace("\n", '', str_replace(CRLF, '', $line)));
                         if (substr($line, 0, 1) != '2' && substr($line, 0, 1) != '3')
                         {
                              $result = false;
                              $error = '[SMTP] Error <<: ' . $line;
                              setGlobalError($erro r);
                              //setGlobalError(sub str($line, 3));
                              break;
                         }
                    }
               
               } while (substr($line, 3, 1) == '-');
               
               if (!$result && $isLog)
               {
                    CApi::Log(getGlobalError(), ELogLevel::Error);
               }
               
               return $result;
          }
          
          /**
           * @param bool $_force
           */
          function resetTimeOut($_force = false)
          {
               static $_staticTime = null;
               
               $_time = time();
               if ($_staticTime < $_time - RESET_TIME_LIMIT_RUN || $_force)
               {
                    @set_time_limit(RESET_TIME_LIMIT);
                    $_staticTime = $_time;
               }
          }
     }
-----------------------------------------------------------------------
So you have a functional sendmail modified file you can send this way?
Back to Top View smallmid's Profile Search for other posts by smallmid
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 06 January 2012 at 1:10pm | IP Logged Quote Igor

WebMail isn't using sendmail directly. And in your case, you might want to check if mail() function is configured in your environment correctly to send mails out, some simple examples from PHP documentation page could be used for that.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
smallmid
Newbie
Newbie


Joined: 19 December 2011
Location: United States
Online Status: Offline
Posts: 7
Posted: 11 January 2012 at 5:53am | IP Logged Quote smallmid

Igor,

Can you contact me directly? Would love to get the script working on the lite version to perhaps move into the pro version.

Thanks,

Michael
Back to Top View smallmid's Profile Search for other posts by smallmid
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 12 January 2012 at 2:21am | IP Logged Quote Igor

Actually, I have revised the code modification and found a problem in it. I'm speaking of the following lines of code:

Code:
if (($head_key)=='To') $hdr_to.=$head_val."\r\n";
elseif (($head_key)=='Subject') $hdr_subj.=$head_val."\r\n";


Those line breaks added are not required, and it's not really required to use ".=" operator as WebMail message only contains one "To:" and one "Subject:" header. Thus, those lines are to be replaced with:

Code:
if (($head_key)=='To') $hdr_to=$head_val;
elseif (($head_key)=='Subject') $hdr_subj=$head_val;


Hope this helps!

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
ashwani40in
Newbie
Newbie
Avatar

Joined: 24 January 2012
Location: India
Online Status: Offline
Posts: 2
Posted: 24 January 2012 at 1:12pm | IP Logged Quote ashwani40in

Hi Igor!

Your last post helped me and I am successful after a week to send the emails without smtp.
So here is the modified code which i have for the latest version

Code:


               $msg = $message->TryToGetOriginalMailMessage();
               $arr = explode("\r\n\r\n", $msg, 2);
               $body = $arr[1];
               $head = explode("\r\n",$arr[0]);
               $hdrs=''; $hdr_to=''; $hdr_subj=''; $head_key='';
               foreach($head as $key => $value)
                    {
                        $head_val=$value;
                        if (($epos=strpos($value,':'))!==false)
                             {
                                 $h ead_key = substr($value,0,$epos); $head_val=substr($value,2+$epos);
                             }
                        if (($head_key)=='To') $hdr_to=$head_val;
                    elseif (($head_key)=='Subject') $hdr_subj=$head_val;
                        else $hdrs.=$value."\r\n";
                    }
               if (($hdr_bcc=($message->Headers->GetHeaderValueByName("BCC")))!="") $hdrs.="Bcc: $hdr_bcc\r\n";
               return (mail($hdr_to, $hdr_subj, $body, $hdrs));




This code should be pasted right under

Code:

     class CSmtp
     {
          /**
           * @param CAccount $account
           * @param WebMailMessage $message
           * @param string $from
           * @param string $to
           * @return bool
           */

          function SendMail($account, $message, $from, $to)
          {


I would suggest this to be added to KB

Many Thanks again
Back to Top View ashwani40in's Profile Search for other posts by ashwani40in Visit ashwani40in's Homepage
 
ashwani40in
Newbie
Newbie
Avatar

Joined: 24 January 2012
Location: India
Online Status: Offline
Posts: 2
Posted: 24 January 2012 at 1:20pm | IP Logged Quote ashwani40in

ashwani40in wrote:
Hi Igor!

Your last post helped me and I am successful after a week to send the emails without smtp.
So here is the modified code which i have for the latest version

Code:


               $msg = $message->TryToGetOriginalMailMessage();
               $arr = explode("\r\n\r\n", $msg, 2);
               $body = $arr[1];
               $head = explode("\r\n",$arr[0]);
               $hdrs=''; $hdr_to=''; $hdr_subj=''; $head_key='';
               foreach($head as $key => $value)
                    {
                        $head_val=$value;
                        if (($epos=strpos($value,':'))!==false)
                             {
                                 &n bsp;$h ead_key = substr($value,0,$epos); $head_val=substr($value,2+$epos);
                             }
                        if (($head_key)=='To') $hdr_to=$head_val;
                    elseif (($head_key)=='Subject') $hdr_subj=$head_val;
                        else $hdrs.=$value."\r\n";
                    }
               if (($hdr_bcc=($message->Headers->GetHeaderValueByName("BCC")))!="") $hdrs.="Bcc: $hdr_bcc\r\n";
               return (mail($hdr_to, $hdr_subj, $body, $hdrs));




This code should be pasted right under

Code:

     class CSmtp
     {
          /**
           * @param CAccount $account
           * @param WebMailMessage $message
           * @param string $from
           * @param string $to
           * @return bool
           */

          function SendMail($account, $message, $from, $to)
          {


I would suggest this to be added to KB

Many Thanks again


I forgot to add I am using AfterLogic WebMail Pro 6 PHP
Back to Top View ashwani40in's Profile Search for other posts by ashwani40in Visit ashwani40in's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide