<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Joe's Amazing Technicolor Weblog &#187; email</title>
	<atom:link href="http://slagwerks.com/blog/index.php/tag/email/feed/" rel="self" type="application/rss+xml" />
	<link>http://slagwerks.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 23 Jul 2010 22:31:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Sending email from FileMaker via PHP, revisited</title>
		<link>http://slagwerks.com/blog/index.php/2008/10/22/sending-email-from-filemaker-via-php-revisited/</link>
		<comments>http://slagwerks.com/blog/index.php/2008/10/22/sending-email-from-filemaker-via-php-revisited/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 15:57:01 +0000</pubDate>
		<dc:creator>joe</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[FileMaker]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://slagwerks.com/blog/?p=118</guid>
		<description><![CDATA[We last looked at this a few months ago, but have been revisiting it to come up with something a little more robust.&#160;Notes: there&#8217;s a good overview of using PHP with FM at the sixfriedrice&#160;blog. the API for FileMaker&#8217;s PHP interface is available at&#160;http://YOURSERVER.URL:16000/docs/PHP%20API%20Documentation/index.html I&#8217;d missed this last time around, but accounts &#38; permissions are [...]]]></description>
			<content:encoded><![CDATA[<p>We last looked at this <a href="http://slagwerks.com/blog/index.php/2008/06/12/sending-server-side-emails-from-filemaker-via-php/  ">a few months ago</a>, but have been revisiting it to come up with something a little more robust.&nbsp;Notes:</p>
<ul>
<li>there&#8217;s a good overview of using <span class="caps">PHP</span> with <span class="caps">FM</span> <a href="http://sixfriedrice.com/wp/up-to-speed-with-the-filemaker-php-api/">at the sixfriedrice&nbsp;blog</a>.</li>
<li>the <span class="caps">API</span> for FileMaker&#8217;s <span class="caps">PHP</span> interface is available at&nbsp;http://<span class="caps">YOURSERVER</span>.<span class="caps">URL</span>:16000/docs/<span class="caps">PHP</span>%<span class="caps">20API</span>%20Documentation/index.html</li>
<li>I&#8217;d missed this last time around, but accounts <span class="amp">&amp;</span> permissions are a little funky. <em>fmphp</em> needs to be added to the Extended Privileges of the database you&#8217;re trying to get to, and must have the same privilege set as the account you&#8217;re connecting&nbsp;as.</li>
<li>The solution we settled on is a <span class="caps">CLI</span> <span class="caps">PHP</span> script running hourly, checking for mail to send. Launchd would be the logical way to do the scheduling, but always drives me nuts. Fortunately the server in question has cron set up (so much&nbsp;simpler!)</li>
</ul>
<p>The code we&#8217;re more or less&nbsp;using:</p>
<pre><code>
#!/usr/bin/php
&lt;?php
set_include_path(get_include_path() . PATH_SEPARATOR .
  '/Library/FileMaker Server/Web Publishing/publishing-engine/php/lib/php/');
require_once('FileMaker.php');

echo "PHP email-sending-script, running at " .
  date('m/d/Y H:i') . "\n";
$layout = 'Outgoing_Email';
$fm = new FileMaker('Layout Name');
$fm-&gt;setProperty('username', 'your filemaker username');
$fm-&gt;setProperty('password', 'your filemaker password');

$findCmd =&amp; $fm-&gt;newFindCommand($layout);
$findCmd-&gt;addFindCriterion('Sent_Flag', '&lt; 1');
$result = $findCmd-&gt;execute();
if (FileMaker::isError($result)) {
  if ($result-&gt;code == 401) {
    exit("No emails to send.\n");
  } else {
    exit("trouble: " . $result-&gt;message . "(" . $result-&gt;code . ")");
  }
}

$records = $result-&gt;getRecords();
foreach($records as $record) {
  echo "To: " . $record-&gt;getField('Recipient') . "\n";
  echo "Subject: " . $record-&gt;getField('Subject') . "\n";
  $headers = array(
    "From: filemaker@example.com",
    "MIME-Version: 1.0",
    "Content-type: text/html"
    );

  /*
   FM helpfully encodes &lt; and &gt;...
   */
  $body = preg_replace('/&amp;lt;/', '&lt; ', $record-&gt;getField('Body'));
  $body = preg_replace('/&amp;gt;/', '&gt;', $body);
  $rc = mail($record-&gt;getField('Recipient'),
       $record-&gt;getField('Subject'),
       $body,
       implode("\r\n", $headers)
      );
  if ($rc) {
    $update = $fm-&gt;newEditCommand($layout, $record-&gt;getRecordId());
    $update-&gt;setField('Sent_Date', date('m/d/Y'));
    $update-&gt;setField('Sent_Time', date('H:i'));
    $update-&gt;setField('Sent_Flag', '1');
    $result = $update-&gt;execute();
    if (FileMaker::isError($result)) {
      exit("trouble updating the database after sending email: " .
        $result-&gt;message . "(" . $result-&gt;code . ")");
    }
    echo "Mailed!\n";
  } else {
    exit("Mail didn't work.\n");
  }
}

</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://slagwerks.com/blog/index.php/2008/10/22/sending-email-from-filemaker-via-php-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>setting up Google Apps at my nonprofit</title>
		<link>http://slagwerks.com/blog/index.php/2008/08/11/setting-up-google-apps-at-my-nonprofit/</link>
		<comments>http://slagwerks.com/blog/index.php/2008/08/11/setting-up-google-apps-at-my-nonprofit/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 15:37:32 +0000</pubDate>
		<dc:creator>joe</dc:creator>
				<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[google apps]]></category>
		<category><![CDATA[nonprofit]]></category>

		<guid isPermaLink="false">http://slagwerks.com/blog/?p=65</guid>
		<description><![CDATA[We already had a serviceable in-house email server, so why change? In no particular&#160;order, Cost savings. We&#8217;d been spending $1k+ annually on postini&#8217;s spam protection service alone, which Google Apps conveniently bundles in for free. Also a maintenance contract on the email software, depreciation on the server,&#160;electricity One less server to&#160;manage Far superior webmail and [...]]]></description>
			<content:encoded><![CDATA[<p>We already had a serviceable in-house email server, so why change? In no particular&nbsp;order,</p>
<ul>
<li> Cost savings. We&#8217;d been spending $1k+ annually on postini&#8217;s spam protection service alone, which Google Apps conveniently bundles in for free. Also a maintenance contract on the email software, depreciation on the server,&nbsp;electricity</li>
<li>One less server to&nbsp;manage</li>
<li>Far superior webmail and group calendaring to what we&#8217;ve been&nbsp;using</li>
</ul>
<p>When first thinking about doing this conversion I talked to a bunch of people whose organizations were already using google apps. Nobody really had any complaints. Given the upside, I certainly don&#8217;t feel like I&#8217;m in a position to complain, either, but I thought it&#8217;d be worth mentioning a few issues I&nbsp;encountered:</p>
<ul>
<li>I applied July 22nd for nonprofit status, and heard back (in the affirmative) on August 5th. Fortunately, it&#8217;s entirely possible to switch over with just a standard account, but I wish I&#8217;d applied earlier and not had to worry about whether or not that was going to go&nbsp;through.</li>
<li>While it&#8217;s nice that there&#8217;s an open source <a href="http://code.google.com/p/google-apps-for-your-domain-ldap-sync/"><span class="caps">LDAP</span> solution for syncing user accounts</a>, it <a href="http://code.google.com/p/google-apps-for-your-domain-ldap-sync/issues/detail?id=15">has had some issues</a> and even when working it only handles people&#8217;s names, email addresses, and passwords. At the time I was working with it, the best bet was to use the latest tarball, into whose directory I had to copy the above-mentioned file. Even after that, I continued to have enough trouble to abandon ship&thinsp;&#8212;&thinsp;was quicker to do the work by hand than to fix the bugs.<br />
In case anyone&#8217;s also trying to hook this tool up with Apple&#8217;s Open Directory, I had some initial luck with the following:<br />
<code>Command: set ldap_url LDAP://servername.example.org<br />
Command: set ldap_base_dn dc=servername,dc=example,dc=org<br />
Command: set ldap_user_filter (objectclass=apple-group)</code><br />
though it doesn&#8217;t look like anyone&#8217;s worked through the mapping from Apple&#8217;s schema.<br />
Beyond just working stably, it would be great if group membership could be used to configure mail lists&thinsp;&#8212;&thinsp;I see that&#8217;s listed under <a href="http://code.google.com/p/google-apps-for-your-domain-ldap-sync/wiki/HowToUseIt">possible improvements</a> (bottom of page). I&#8217;ll try to take a look at that some day <span class="amp">&amp;</span> see how feasible it would be to work it&nbsp;in.</li>
<li>Transferring old emails is a pain if you&#8217;re not on a mainstream email server (raise your hand if you&#8217;ve heard of Stalker Software&#8217;s <a href="http://www.communigate.com/enterprise/solutions.html">Communigate Pro</a>). We&#8217;re doing it by setting both the old and new servers up in the same email client <span class="amp">&amp;</span> copying messages over through it, but then we lose the date emails were sent /&nbsp;received.</li>
<li>I couldn&#8217;t find any way to turn on <span class="caps">IMAP</span> access across the board, so I did a lot of logging in <span class="amp">&amp;</span> setting people&#8217;s account preferences. This wouldn&#8217;t be a big deal if it weren&#8217;t for the old email transferring issue mentioned&nbsp;above.</li>
<li>While it&#8217;s possible to create an email list containing all addresses in the domain, only admins can send mail to it; to get an all-staff list, I had to actually type everybody&#8217;s address in. More motivation to work on the <span class="caps">LDAP</span> group-to-list mapping mentioned&nbsp;above.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://slagwerks.com/blog/index.php/2008/08/11/setting-up-google-apps-at-my-nonprofit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sending server-side emails from FileMaker via PHP</title>
		<link>http://slagwerks.com/blog/index.php/2008/06/12/sending-server-side-emails-from-filemaker-via-php/</link>
		<comments>http://slagwerks.com/blog/index.php/2008/06/12/sending-server-side-emails-from-filemaker-via-php/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 23:15:54 +0000</pubDate>
		<dc:creator>joe</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[FileMaker]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://slagwerks.com/blog/?p=57</guid>
		<description><![CDATA[Some context&#8201;&#8212;&#8201;my new gig features a big &#8216;ol FileMaker installation, which has a number of automated maintenance routines. Some of those routines send emails, through a convoluted process involving FileMaker calling a GUI MUA (e.g. Mail.app). There are a number of practical problems with this, such as the requirement of another computer running, always logged [...]]]></description>
			<content:encoded><![CDATA[<p>Some context&thinsp;&#8212;&thinsp;my new gig features a big &#8216;ol <a href="http://en.wikipedia.org/wiki/FileMaker">FileMaker</a> installation, which has a number of automated maintenance routines. Some of those routines send emails, through a convoluted process involving FileMaker calling a <span class="caps">GUI</span> <span class="caps">MUA</span> (e.g. Mail.app). There are a number of practical problems with this, such as the requirement of another computer running, always logged into an account capable of sending the&nbsp;emails.</p>
<p>We&#8217;d done a bit of research about strictly server-side alternatives, and found surprisingly little. The best resource was <a href="http://www.grahamsprague.com/server_side_email/server_side_email.html">Graham Sprague&#8217;s page about sending emails via FileMaker&#8217;s <span class="caps">XSLT</span> Web Publishing tool</a>. We gave that approach a try, but didn&#8217;t get any results, or anything useful from FileMaker&#8217;s logs to explain why things weren&#8217;t working. I&#8217;m not sure what FileMaker version Graham&#8217;s example was written for, perhaps something&#8217;s changed with version&nbsp;9?</p>
<p>Rather than dive into FileMaker&#8217;s proprietary <span class="caps">XSLT</span> system to debug things, it occurred to me that this might be a job for FileMaker&#8217;s <span class="caps">PHP</span> <span class="caps">API</span>. Sure enough, after about 15 minutes of consulting the <span class="caps">API</span> Doc, we were sending emails based on the contents of a FileMaker&nbsp;record. </p>
<p>We&#8217;re still working on ironing out the details, but here&#8217;s the rough proof of concept <span class="caps">PHP</span> file. It works with the example email database from Graham&#8217;s <span class="caps">XSLT</span> sample, with the php permission added to the database. Plenty of missing features such as cc <span class="amp">&amp;</span> bcc fields, actually checking for the &#8216;send&#8217; flag, checking for errors, any kind of authorization or authentication, etc. In other words, you probably don&#8217;t want to be running this on a publicly accessible webserver, but at least it presents the basic idea in a simple&nbsp;form.</p>
<pre><code>
&lt;?php
require_once('FileMaker.php');
$fm = new FileMaker();
$fm->setProperty('username', 'send_email');
$fm->setProperty('password', 'whatever_the_password_is');
$fm->setProperty('database', 'Email');

$findCmd =&#038; $fm->newFindAllCommand('Utility_Email');
$result = $findCmd->execute();
$records = $result->getRecords();
foreach($records as $record) {
  $headers = array("From: " . $record->getField('from'));

  mail($record->getField('to'),
       $record->getField('subject'),
       $record->getField('message'),
       implode("\r\n", $headers)
      );
}
echo "Emails sent";
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://slagwerks.com/blog/index.php/2008/06/12/sending-server-side-emails-from-filemaker-via-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
