Phalcon\Mail component

1,163 views
Skip to first unread message

hdo...@gmail.com

unread,
Oct 22, 2012, 5:13:14 AM10/22/12
to phalcon-...@googlegroups.com
Hello there!

I've already started to work on Phalcon\Mail component and I'm slowly getting familiar with Zend and Phalcon internal APIs. Since Zend has lack of documentation it takes much more time than I planned.

Well, I planned to use just 2 classes for mail component:

1) Phalcon\Mail (It's about same as Switf_Message - but I don't like to use "message" as class naming, it's too general).
2) Phalcon\Mail\Transport classes (at first I'm planning to implement Phalcon\Mail\Transport\PHP at first which use PHP's "mail" function)

The usage will be about same as Switf mailer except it will not be static class (or should it be?)

Here is the quick sample code:

<?php
$options = array("from" => "m...@notme.com", "subject" => "first subject", "transport" => "see below for passing transport layer");

$mail = new Phalcon\Mail($options);
$mail->setSubject("bla bla"); // overwrites subject
$mail->setBody("bla bla bla");
$mail->send();
?>

You can pass all options with $options parameter or just use separate setter methods.

So Phalcon\Mail send() method will use transport's send() method. It will pass whole options (protected property) to transport layer.

I haven't decided to i should pass transport class name or instance to options parameter or to setTransport() method.

$mail->setTransport(new Phalcon\Mail\Transport\PHP); or
$mail->setTransport("PHP"); // it will be prepended with Phalcon\Mail\Transport\ in internal side.

I haven't decided should i implement dummy Transport class, so people can extend and write their own transport classes with using PHP. [maybe with next release?]

Also I use setOptions and getOptions methods to take care of all option handling. So other setter/gettter methods (ie, setSubject) direcly calls setoptions/getoptions with sending parameters. All job is done by setOptions/getOptions. I strictly checking all parameters and their types (ie, subject must be a string, from must be a string or an array, etc).

As for attachments, I'm not planning to use separate class for them. I'll big probably implement addAttachment method which takes string or array parameter.

I'll try to push my first implementation on my fork on Github by today.

Take care.

Hidayet Dogan

Wojtek Gancarczyk

unread,
Oct 22, 2012, 5:26:45 AM10/22/12
to phalcon-...@googlegroups.com
Hi Hidayet,

will I be able to send multipart messages? Will I be able to embed images? 

As for the dummy Transport class, I'm a big fan of interfaces and correct me if I'm wrong, but Phalcon takes that approach too. From my experience I would also say, if you provide SMTP and PHP Transport layers, it should cover most of the cases.

Thanks for your work, looking forward to try it out!

Best
Wojtek

hdo...@gmail.com

unread,
Oct 22, 2012, 5:35:38 AM10/22/12
to phalcon-...@googlegroups.com
Yes and yes, it will support multipart and inline images.

I'm still trying to find solution for SMTP transport layer. I think it should support TLS layer too, so it will big probably takes much more time to implement. I'm still researching a solution.

Hidayet Dogan

Nikolaos Dimopoulos

unread,
Oct 22, 2012, 8:56:53 AM10/22/12
to phalcon-...@googlegroups.com
Hey Hidayet,

Transport: I would keep things simple and pass the object. The second example $mail->setTransport('PHP') is nice but it starts over complicating code which is not what we want. Everyone is used to the idea of setting an object to a class so the new Phalcon\Mail\Transport\PHP is going to work just fine. 

In the 0.7.0 version, a lot of work is scheduled for interfaces. Almost everything will be interfaced in Phalcon to allow users to create their own components and inject them in there. Since you are building this from scratch, please keep that in mind.

The release schedule will be announced shortly - it was only last night that I was working with Andres to finalize it.

GREAT job!!!

One favor/feature to ask: If possible can you provide "cleanup" functions? For instance $mail->removeRecipients(), $mail->removeRecipient('x...@z.com') or $mail->removeAttachments()?

I recall working with Zend Mail and there was no way for us to remove a recipient, so when we wanted to send 100 emails out with the same subject and one attachment, we had to instantiate the mail object 100 times o_O

Thanks!!!

Hidayet Doğan

unread,
Oct 22, 2012, 10:20:29 AM10/22/12
to Nikolaos Dimopoulos, phalcon-...@googlegroups.com
Hello,

I'm on the half way except completing send methods of transport adapters.

I have currently these classes and methods:

Phalcon\Mail
__construct([optional] array options)
Construct the class and call setOptions if optional "options" parameter given.

setOptions(array options);
Sets all options array to protected _options array. Options are like "to", "from", "subject", "transport", etc.

getOptions([optional] string name);
Returns options as an array, if optional "name" parameter is given it returns option value (string|array|object)

_getAddressList(array|string addresses) - private
Parses addresses for internal use.

setId(string id)
getId (Message Id)

setType(string type, [optional]string charset);
getType (Content-Type)

setCharset(string charset)
getCharset (content-type charset)

setTransport(object Phalcon\Mail\Transport)
getTransport

setFrom(string|array from)
getFrom

setTo(string|array to)
getTo

setCc(string|array cc)
getCc

setBcc(string|array bcc)
getBcc

send() - this will pass all options/headers to transport adapter and fire adapter's "send" method.

Phalcon\Mail\Transport - abstract class
__construct - public
send - protected | abstract

Phalcon\Mail\Transport\PHP - extends from Phalcon\Mail\Transport
send - protected

I'll continue implementing other properties like replyTo, return-path, etc.

Here are the sample code:

$transport = new Phalcon\Mail\Transport\PHP; // PHP adapter, will use "mail" function.

$mail = new Phalcon\Mail(array(
    'to' => 't...@address.com',
    'from' => array('fr...@address.com', 'From Name'),
    'subject' => 'Test mail',
    'transport' => $transport
));

$mail->setBody("bla bla");
$mail->send();

--
Hidayet Doğan
http://hi.do


--
 
 

hdo...@gmail.com

unread,
Oct 29, 2012, 6:41:11 AM10/29/12
to phalcon-...@googlegroups.com
I think mail component is a bit delayed because of the local IT conference will be hold next week. I'll introduce Phalcon (and another two php related keynotes) at there and I haven't completed my keynotes yet :)

I was planning to complete it by next week but I think first running implementation will be done about mid November.

By the way, I used mb_detect_encoding, mb_encode_mimeheader and quoted_printable_encode PHP functions for header/body manipulation (to follow RFCs) which requirements are pushed to PHP >= 5.3.0 and mbstring extension installed. I hope it will not cause any problem for Phalcon distribution, else I have to find hardest way to mimic these functions (I hate to work on strings).

Nikolaos Dimopoulos

unread,
Oct 29, 2012, 11:47:40 AM10/29/12
to hdo...@gmail.com, phalcon-...@googlegroups.com
Hidayet,

There is plenty of time. This week coming 0.6.0 is being released and the Mail component is not "due" until 0.7.0.

With that being said, this is an open source project and by no means does anyone think that we don't have personal lives and that things might get delayed :)

Thanks for the contributions and the heads up and keep up the good work!

Nikos

The contents of this message may contain confidential or privileged information and is intended solely for the recipient(s). Use or distribution to and by any other party is not authorized. If you are not the intended recipient, copying, distribution or use of the contents of this information is prohibited.


--
 
 

Reply all
Reply to author
Forward
0 new messages