Mailing for Thinkup – Hacking a Solution without using Sendmail

I’ve been meaning to try Thinkup for a long time now, and finally got around to trying it out.

I also decided this was also a good time to try a RaspberryPi and so the system I ended up running it on was not as complete as a normal linux server, or commercially provided host.

After installing dependencies, I quickly got stymied when I did not get a confirmation email.

Apparently this isn’t unique:

http://thinkupapp.com/docs/troubleshoot/common/emaildisabled.html

Also, their guidance is that; “We strongly recommend running ThinkUp on a web server which can send email.”

Using GMail as my SMTP server seemed the obvious choice, but that was before I learned that PHP’s mail() function does not support authentication in any way.

Apparently the most popular solution I found on Google was to use PHPMailer and this required some hacking that I wanted to document here.

I’m not sure if all of these steps are necessary, but it worked for me (TM):

  1. sudo vi /etc/php5/cgi/php.ini
    Add the line extension=php_openssl.so
  2. Download PHPMailer and extract it into your thinkup _lib directory [for me this was /usr/share/nginx/www/thinkup/_lib]
  3. Hack /usr/share/nginx/www/thinkup/_lib/class.Mailer
    • Add the following to the beginning of the file [right after "<?php"]: "ini_set("include_path", ".:./PHPMailer_v5.1/");
      require("PHPMailer_v5.1/class.phpmailer.php");
    • Find “} else { mail($to, $subject, $message, $mail_header);" and comment it out [with //]
    • then add:
      /** KLUDGE ADDED - START **/
      $mail = new PHPMailer();
      $mail->IsSMTP();
      // $mail->SMTPDebug = 2;
      $mail->SMTPAuth = true;
      $mail->SMTPSecure = "tls";
      $mail->Host = 'smtp.gmail.com';
      $mail->Port = 587;
      $mail->Username = "YOURNAME@gmail.com";
      $mail->Password = "YOURPASSWORD";
      $mail->SetFrom("YOURNAME@gmail.com", "thingkup_notifications");
      $mail->AddAddress($to);
      $mail->Subject = $subject;
      $mail->Body = $message;
      $mail->WordWrap = 50;
      if(!$mail->Send()) {
      echo ‘Message was not sent.';
      echo ‘Mailer error: ‘ . $mail->ErrorInfo;
      }
      else {
      echo ‘Message has been sent.';
      }
      /** KLUDGE ADDED – END **/

I hope that helps someone, I can’t say it’s extensively tested (I wanted to blog it all before I forgot) but it worked in my example test script, which has to be close enough, right!

About jay

I'm trying to build something interactive where I can learn from others and hopefully share useful knowledge too. thecapacity@gmail.com
This entry was posted in code, opensource. Bookmark the permalink.