Sarath

Send private message

You must be logged in to send a private message.

Friends

No friends yet.

Group membership

Activity

  • Sarath replied on the discussion topic zend-mail
    @Claudius: please update if its working for you. For me it was not working even after making those changes.  Please see Configuring SMTP settings : Elgg.org view reply
  • Sarath joined the group General Discussion
  • Following is my code. I am able to retrieve subject and body, but I am not getting the from and to... view reply
  • Hi, After having a lot of failed attempts in configuring elgg smtp for amazon ses, i thought of connecting to SES via smtp. For elgg 2.3 branch, I am able to extract the message details like from, to, body, subect etc using...
    • Following is my code. I am able to retrieve subject and body, but I am not getting the from and to address.

      elgg_register_plugin_hook_handler('transport''system:email''phpmailer_hook');
      function phpmailer_hook($hook, $type, $return, $params) {
          $email = $params['email'];
          $from = $email->getFrom();
          $to = $email->getTo();
          $subject = $email->getSubject();
          $body = $email->getBody();
          // .....
      }
    • The email parameter should be an instance of \Elgg\Email.

      Learn docs.

       

  • Sarath replied on the discussion topic Configuring SMTP settings
    @Reuven: Thanks for that script. That was a good starting point for me. I modified this and used Cash's php mailer plugin too to connect to SES via smtp. Now its working in Elgg 2.3 branch. view reply
  • Sarath replied on the discussion topic Configuring SMTP settings
    @Nikolai: tried all those permutations and combinations before posting the ticket :) @Reuven: Thanks a lot for that. Let me give it a try. view reply
  • Sarath replied on the discussion topic Help needed in setting up Cache path in settings.php
    Thank Nikolai. Let me try that. view reply
  • Sarath added a new discussion topic Configuring SMTP settings in the group Elgg Technical Support
    My site is using ses for the smtp service. To use that I tried following configuration in config...
    • With the help of iionly I've developed a plugin that works well with Amazon ses, for elgg 2.3.14

      All the relevant code is in start.php (below). Also, you need to install the appropriate Amazon AWS sdk.

      Hope it help you.

      <?php
      require_once(dirname(__FILE__) . '/Amazon-AWS-SDK/aws-autoloader.php');
      use Aws\Ses\SesClient;
      use Aws\Ses\Exception\SesException;
       
      elgg_register_event_handler('init', 'system', 'amazon_ses_init');
       
      function amazon_ses_init() {
         elgg_register_plugin_hook_handler('email', 'system', 'amazon_ses_send_email');
      }
       
      function amazon_ses_send_email($hook, $type, $returnvalue, $params) {
          if (!is_array($returnvalue) || !is_array($returnvalue['params'])) {
              return;
          }
       
          $to_address = '';
          $contact = $returnvalue['to'];
          $containsName = preg_match('/<(.*)>/', $contact, $matches) == 1;
          if ($containsName) {
              $to_address = $matches[1];
          } else {
              $to_address = $contact;
          }
       
          if (!$to_address) {
              return $returnvalue;
          }
       
          $users = get_user_by_email($to_address);
          $recipient = $users[0];
       
          if (!($recipient instanceof ElggUser)) {
              return $returnvalue;
          }
          
          $subject = $returnvalue['subject'];
          $from = $returnvalue['from'];
          
          $site_url = elgg_get_site_url();
      $notification_settings_url = $site_url . '/notifications/personal/' . $recipient->username;
      $group_notification_settings_url =  $site_url . '/notifications/group/' . $recipient->username;
      $recipient_language = ($recipient->language) ? $recipient->language : (($site_language = elgg_get_config('language')) ? $site_language : 'en');
          
          $originalMessage = $returnvalue['body'];
          /** ===== Prepare the HTML message ====== */
      $messageHTML = $originalMessage.elgg_echo('amazon_ses:content', [$to_address, $site_url, $notification_settings_url, $group_notification_settings_url], $recipient_language);
          /** ===== Prepare the TEXT message ======
           * ======= remove HTML tags =============== */
          $messageTEXT = preg_replace('/<.*?>/s', '', $messageHTML);
          
          /** ===== replace non-breaking space with regular space =============== */
          $messageTEXT = preg_replace('/&nbsp;/', ' ', $messageTEXT);
        /** ===== Amazon SES Starts ===== */  
          $client = SesClient::factory([
              'version'=> 'latest',
              'region' => 'us-east-1'
          ]);
          $charset = 'UTF-8';
       
      try {
      if(preg_match('/<.*?>/s',$originalMessage)){// == if there are HTML tags send HTML and TEXT emails
           $result = $client->sendEmail([
              'Destination' => [
                  'ToAddresses' => [
                      $to_address,
                  ],
              ],
              'Message' => [
                  'Body' => [
                      'Html' => [
                          'Charset' => $charset,
                          'Data' => $messageHTML,
                      ],
                      'Text' => [
                          'Charset' => $charset,
                          'Data' => $messageTEXT,
                      ],
                  ],
                  'Subject' => [
                      'Charset' => $charset,
                      'Data' => $subject,
                  ],
              ],
          'Source' => $from, 
        ]);  
        }else{// === If no HTML tags - send only TEXT email
          
              $result = $client->sendEmail([
              'Destination' => [
                  'ToAddresses' => [
                      $to_address,
                  ],
              ],
              'Message' => [
                  'Body' => [
                      'Text' => [
                          'Charset' => $charset,
                          'Data' => $messageTEXT,
                      ],
                  ],
                  'Subject' => [
                      'Charset' => $charset,
                      'Data' => $subject,
                  ],
              ],
          'Source' => $from, 
        ]);
          
        }
              $messageId = $result->get('MessageId');
       
              return true;
          } catch (SesException $error) {
              $errorMessage = $error->getAwsErrorMessage();
              
              $message .= $messageTEXT.' ..... send by mail.';
       
              $headers = "From: $from"; 
              if(mail($to_address,$subject,$message,$headers)!==false){
                  return true;
              }               
          }
          return $returnvalue;
      }
    • @Nikolai: tried all those permutations and combinations before posting the ticket :)

      @Reuven: Thanks a lot for that. Let me give it a try.

    • @Reuven: Thanks for that script. That was a good starting point for me. I modified this and used Cash's php mailer plugin too to connect to SES via smtp. Now its working in Elgg 2.3 branch.