Message from discussion
RFC - sending emails with symfony 1.2
Received: by 10.100.195.15 with SMTP id s15mr9094158anf.20.1221480562550;
Mon, 15 Sep 2008 05:09:22 -0700 (PDT)
Return-Path: <nperria...@gmail.com>
Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.173])
by mx.google.com with ESMTP id 22si8011937yxr.1.2008.09.15.05.09.21;
Mon, 15 Sep 2008 05:09:22 -0700 (PDT)
Received-SPF: pass (google.com: domain of nperria...@gmail.com designates 66.249.92.173 as permitted sender) client-ip=66.249.92.173;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of nperria...@gmail.com designates 66.249.92.173 as permitted sender) smtp.mail=nperria...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by ug-out-1314.google.com with SMTP id j30so1154291ugc.22
for <symfony-devs@googlegroups.com>; Mon, 15 Sep 2008 05:09:20 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:received:received:message-id:date:from:to
:subject:mime-version:content-type:content-transfer-encoding
:content-disposition;
bh=C4tk0trcn4hBLbTa/y939EwsfNUvZisnDfBFN+deL3g=;
b=FYnHKls1h5RJJQNzsCN7y90mb94ZFdZItfHBQ5mGalJUTCFc/PN4O1sgY/VqyP0y1F
qTdPPF0ijSw/pwA7Fyy5rs5e+e/YHVMnTxsQqAhK9OPRMc7Jugh+G3LXm+nTbgsLiggl
SjUSVJL1KK66l+RP/CK7kz/Bv3ySM03P7sKks=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=message-id:date:from:to:subject:mime-version:content-type
:content-transfer-encoding:content-disposition;
b=CVbGLqUFvvMxoFOA+x1GYdcZIFznZ8NAiVBULU41ceiy7RtvZHIUeMGwNAAF2DEh/5
dRGCpWh+SS7wBIAeNlwsGI+4xiHS/GJGk2j3/bC41y2iJlsJTCMfVgxBKlWyI8CTUHFZ
kJayV70HCzUkKUp6BaxVhIyD0Fs2aVGw9BqGs=
Received: by 10.67.93.16 with SMTP id v16mr3140755ugl.1.1221480560734;
Mon, 15 Sep 2008 05:09:20 -0700 (PDT)
Received: by 10.66.252.11 with HTTP; Mon, 15 Sep 2008 05:09:20 -0700 (PDT)
Message-ID: <4ff025930809150509r3686d86by268f6de33ad63142@mail.gmail.com>
Date: Mon, 15 Sep 2008 14:09:20 +0200
From: "Nicolas Perriault" <nperria...@gmail.com>
To: "Symfony devs" <symfony-devs@googlegroups.com>
Subject: RFC - sending emails with symfony 1.2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi devs,
As you may know, I'm in charge of providing a standard way to send
emails within symfony 1.2. I'd like to get your feedback and ideas
about the way the SwiftMailer library goodness should be integrated.
Currently I've just played with Swift and nothing has really been
started by my side, so everything is still possible =)
To me, the main important thing if to be able to use a different
mailer dependending of the environment: maybe in dev mode you doesn't
want to send real email, but just want to generate them and store them
on your local filesystem (or anywhere you want), as the sfEmailPlugin
does. That would be possible using the factories.yml file, like this:
prod:
mailer:
class:
sfMailerSmtp:
server: foo.bar.tld
port: 25
username: foo
password: bar
default_sender: Toto Mailer <t...@toto.com>
all:
mailer:
class:
sfMailerLocalFilesystem:
path: %SF_LOG_DIR%/emails
My main concern here is that it will be hard to bundle it as a plugin,
because I do not know any way to hook/override the factories
configuration in symfony within a plugin context... Maybe a smart
approach would be to provide base abstract classes in the symfony
core, and the plugin would provide a Swift based implementation? I
don't know, but it looks like if not possible, we'll must implement
this feature in the core...
I was also thinking about creating dedicated message classes (as Swift
already does) but with native symfony-based mail contents generation
available, to ease mail objects reuse. Maybe something like this
(rough draft):
$email = new sfEmail();
// then
$email->setHtmlContentResolver(sfEmail::FROM_ACTION, array('mymodule',
'myaction'));
// or
$email->setTextContentResolver(sfEmail::FROM_PARTIAL,
array('mymodule', 'mypartial'));
// or
$email->setTextContentResolver(sfEmail::FROM_COMPONENT,
array('mymodule', 'mycomponent'));
// or
$email->setTextContentResolver(sfEmail::FROM_STRING, 'hello world');
// and maybe
$email->setContentResolver('text/html', sfEmail::FROM_STRING, 'hello world');
// why not
$email->setContentResolver('application/pdf', sfEmail::FROM_FILE,
'/tmp/toto.pdf');
// there could be also sfEmail::FROM_CALLBACK and so on
// then
$email->send();
It's a bit verbose, eh? Maybe we can also use dedicated classes for
email templates, eg. sfEmailTemplateAction, sfEmailTemplateComponent,
etc., but maybe it's a bit bloated by design for the purpose of just
sending emails? Swift has native support fr template, maybe just
extending it with these sfEmail templates classes could be a solution?
For custom reuseable emails, we should be able to easily create
dedicated email classes:
class myEmail extends sfEmail
{
public function configure()
{
// configure the email here, eg.
$this->setSubject('Hello there');
}
}
These classes would be stored in a new lib/email directory by default,
maybe with a stub BaseEmail class available for user level generic
implementation purpose: sfEmail < BaseEmail < myEmail.
At the end, I would like to be able do do things like that:
class fooActions extends sfActions
{
public function executeBuy($request)
{
if ($request->isMethod('post))
{
$email = new myEmail();
$email->addTo('t...@toto.com');
$email->setVars(array($request->getAttribute('stuff')));
$email->send();
}
}
}
So here are my actual thoughts. What are your ideas and suggestions?
++
--
Nicolas Perriault
http://prendreuncafe.com - http://symfonians.net - http://sensiolabs.com
Phone: +33 660 92 08 67