librelist archives

« back to archive

Mail Flask extension

Mail Flask extension

From:
Dan Jacob
Date:
2010-05-28 @ 15:26
I'm thinking of doing a Flask mail extension using TurboMail, as this
seems to have the most functionality out of the box (multipart
messages, attachments etc).

The application would work something like this:

from flask import Flask
from flaskext.mail import init_mail

def create_app(config):
    app = Flask(__name__)
    app.config.from_pyfile(config)

    init_mail(app)

then in your code:

from flaskext.mail import Message

msg = Message(subject, from_addr, recipients)
msg.plain = "hello"
msg.send()

However to prevent duplication of effort I'd like to ask any Flask developers:

1) Is anyone aware of better libraries out there than TurboMail ?
2) Does anyone know of a good reason NOT to use TurboMail ?
3) Is anyone else working on this as well ?

Re: [flask] Mail Flask extension

From:
Armin Ronacher
Date:
2010-05-28 @ 15:50
Hi,

On 5/28/10 5:26 PM, Dan Jacob wrote:
> 1) Is anyone aware of better libraries out there than TurboMail ?
What's wrong with standard library's smtplib and email package?  There 
is also lamson which has a huge number of well written email tools.

> 2) Does anyone know of a good reason NOT to use TurboMail ?
It has interface.start() / interface.stop() which work process wide 
which sucks for web applications :(

> 3) Is anyone else working on this as well ?
Not me, but I would love to see something not being based on turbomail.


Regards,
Armin

Re: [flask] Mail Flask extension

From:
Stephane Wirtel
Date:
2010-05-28 @ 15:57
Hi all,

Dan, I think you can use the lamson project from Zed Shaw.

Written with Python, and certainly tested with some websites.

May be Librelist ? but I'm not sure.

Regards
On 05/28/2010 05:50 PM, Armin Ronacher wrote:
> Hi,
> 
> On 5/28/10 5:26 PM, Dan Jacob wrote:
>> 1) Is anyone aware of better libraries out there than TurboMail ?
> What's wrong with standard library's smtplib and email package?  There 
> is also lamson which has a huge number of well written email tools.
> 
>> 2) Does anyone know of a good reason NOT to use TurboMail ?
> It has interface.start() / interface.stop() which work process wide 
> which sucks for web applications :(
> 
>> 3) Is anyone else working on this as well ?
> Not me, but I would love to see something not being based on turbomail.
> 
> 
> Regards,
> Armin

Re: [flask] Mail Flask extension

From:
Dan Jacob
Date:
2010-05-28 @ 15:57
On 28 May 2010 16:50, Armin Ronacher <armin.ronacher@active-4.com> wrote:
> Hi,
>
> On 5/28/10 5:26 PM, Dan Jacob wrote:
>> 1) Is anyone aware of better libraries out there than TurboMail ?
> What's wrong with standard library's smtplib and email package?  There
> is also lamson which has a huge number of well written email tools.

Lamson, as I understand it, is more of a complete framework - perhaps
overkill if all you need is a few sendmail-type operations.

If there are some functions available from lamson that can be used
separately of that framework however that might be an option.

>
>> 2) Does anyone know of a good reason NOT to use TurboMail ?
> It has interface.start() / interface.stop() which work process wide
> which sucks for web applications :(
>

Agreed, not something I particularly like either.

>> 3) Is anyone else working on this as well ?
> Not me, but I would love to see something not being based on turbomail.
>

OK.  Probably the way to go is something from standard lib (i.e. email
and smtplib) - the mail package in Django is a possible starting point
in terms of what functionality to cover.

>
> Regards,
> Armin
>

Re: [flask] Mail Flask extension

From:
Armin Ronacher
Date:
2010-05-28 @ 16:02
Hi,

On 5/28/10 5:57 PM, Dan Jacob wrote:
> Lamson, as I understand it, is more of a complete framework - perhaps
> overkill if all you need is a few sendmail-type operations.
In terms of complexity turbomail is probably more a framework than 
lamson is.

> If there are some functions available from lamson that can be used
> separately of that framework however that might be an option.
As far as I know lamson has a utility module with all kinds of lower 
level mail operations.  And you can also use it to start an SMTP server 
locally for development usage which rocks.  So lamson > turbomail for me.

> OK.  Probably the way to go is something from standard lib (i.e. email
> and smtplib) - the mail package in Django is a possible starting point
> in terms of what functionality to cover.
I would try lamson first though.  If that does not work good enough, 
steal individual functions from there and base it on that + smtplib.


Regards,
Armin

Re: [flask] Mail Flask extension

From:
Dan Jacob
Date:
2010-05-28 @ 16:09
I'll have a look at Lamson (actually looking at it already, for an
unrelated work project).

The message object should allow for easy handling of HTML and plain
text messages:

message = Message(...)
message.plain = "hello"
message.html = "<html>hello</html>"
message.send()

Attachments should be easy as well; something like:

message.attach(fp, mimetype)

Any thoughts on this ?

On 28 May 2010 17:02, Armin Ronacher <armin.ronacher@active-4.com> wrote:
> Hi,
>
> On 5/28/10 5:57 PM, Dan Jacob wrote:
>> Lamson, as I understand it, is more of a complete framework - perhaps
>> overkill if all you need is a few sendmail-type operations.
> In terms of complexity turbomail is probably more a framework than
> lamson is.
>
>> If there are some functions available from lamson that can be used
>> separately of that framework however that might be an option.
> As far as I know lamson has a utility module with all kinds of lower
> level mail operations.  And you can also use it to start an SMTP server
> locally for development usage which rocks.  So lamson > turbomail for me.
>
>> OK.  Probably the way to go is something from standard lib (i.e. email
>> and smtplib) - the mail package in Django is a possible starting point
>> in terms of what functionality to cover.
> I would try lamson first though.  If that does not work good enough,
> steal individual functions from there and base it on that + smtplib.
>
>
> Regards,
> Armin
>

Re: [flask] Mail Flask extension

From:
Stephane Wirtel
Date:
2010-05-28 @ 16:21
You can use a html2plain function to convert the html string to a plain text ?

"""
<h1>Title</h1>
Hello,

How are you ?

<a href="http://example.com">Example.com</a>
</html>
"""

The result should be:

"""
Title
=====

Hello,

How are you ?

Example.com [1]

Links:
[1] http://example.com
"""

Regards,

Stephane


On 05/28/2010 06:09 PM, Dan Jacob wrote:
> I'll have a look at Lamson (actually looking at it already, for an
> unrelated work project).
> 
> The message object should allow for easy handling of HTML and plain
> text messages:
> 
> message = Message(...)
> message.plain = "hello"
> message.html = "<html>hello</html>"
> message.send()
> 
> Attachments should be easy as well; something like:
> 
> message.attach(fp, mimetype)
> 
> Any thoughts on this ?
> 
> On 28 May 2010 17:02, Armin Ronacher <armin.ronacher@active-4.com> wrote:
>> Hi,
>>
>> On 5/28/10 5:57 PM, Dan Jacob wrote:
>>> Lamson, as I understand it, is more of a complete framework - perhaps
>>> overkill if all you need is a few sendmail-type operations.
>> In terms of complexity turbomail is probably more a framework than
>> lamson is.
>>
>>> If there are some functions available from lamson that can be used
>>> separately of that framework however that might be an option.
>> As far as I know lamson has a utility module with all kinds of lower
>> level mail operations.  And you can also use it to start an SMTP server
>> locally for development usage which rocks.  So lamson > turbomail for me.
>>
>>> OK.  Probably the way to go is something from standard lib (i.e. email
>>> and smtplib) - the mail package in Django is a possible starting point
>>> in terms of what functionality to cover.
>> I would try lamson first though.  If that does not work good enough,
>> steal individual functions from there and base it on that + smtplib.
>>
>>
>> Regards,
>> Armin
>>

Re: [flask] Mail Flask extension

From:
Dan Jacob
Date:
2010-05-28 @ 16:24
It would be better to manage the plain and html content separately.

On 28 May 2010 17:21, Stephane Wirtel <stephane@wirtel.be> wrote:
> You can use a html2plain function to convert the html string to a plain text ?
>
> """
> <h1>Title</h1>
> Hello,
>
> How are you ?
>
> <a href="http://example.com">Example.com</a>
> </html>
> """
>
> The result should be:
>
> """
> Title
> =====
>
> Hello,
>
> How are you ?
>
> Example.com [1]
>
> Links:
> [1] http://example.com
> """
>
> Regards,
>
> Stephane
>
>
> On 05/28/2010 06:09 PM, Dan Jacob wrote:
>> I'll have a look at Lamson (actually looking at it already, for an
>> unrelated work project).
>>
>> The message object should allow for easy handling of HTML and plain
>> text messages:
>>
>> message = Message(...)
>> message.plain = "hello"
>> message.html = "<html>hello</html>"
>> message.send()
>>
>> Attachments should be easy as well; something like:
>>
>> message.attach(fp, mimetype)
>>
>> Any thoughts on this ?
>>
>> On 28 May 2010 17:02, Armin Ronacher <armin.ronacher@active-4.com> wrote:
>>> Hi,
>>>
>>> On 5/28/10 5:57 PM, Dan Jacob wrote:
>>>> Lamson, as I understand it, is more of a complete framework - perhaps
>>>> overkill if all you need is a few sendmail-type operations.
>>> In terms of complexity turbomail is probably more a framework than
>>> lamson is.
>>>
>>>> If there are some functions available from lamson that can be used
>>>> separately of that framework however that might be an option.
>>> As far as I know lamson has a utility module with all kinds of lower
>>> level mail operations.  And you can also use it to start an SMTP server
>>> locally for development usage which rocks.  So lamson > turbomail for me.
>>>
>>>> OK.  Probably the way to go is something from standard lib (i.e. email
>>>> and smtplib) - the mail package in Django is a possible starting point
>>>> in terms of what functionality to cover.
>>> I would try lamson first though.  If that does not work good enough,
>>> steal individual functions from there and base it on that + smtplib.
>>>
>>>
>>> Regards,
>>> Armin
>>>
>
>

Re: [flask] Mail Flask extension

From:
Stephane Wirtel
Date:
2010-05-28 @ 16:29
ok, it's an example because in the case of OpenERP, we use the 
BeautifulSoup library to convert the html to txt for the mailgateway.

Regards,

Stephane
On 05/28/2010 06:24 PM, Dan Jacob wrote:
> It would be better to manage the plain and html content separately.
> 
> On 28 May 2010 17:21, Stephane Wirtel <stephane@wirtel.be> wrote:
>> You can use a html2plain function to convert the html string to a plain text ?
>>
>> """
>> <h1>Title</h1>
>> Hello,
>>
>> How are you ?
>>
>> <a href="http://example.com">Example.com</a>
>> </html>
>> """
>>
>> The result should be:
>>
>> """
>> Title
>> =====
>>
>> Hello,
>>
>> How are you ?
>>
>> Example.com [1]
>>
>> Links:
>> [1] http://example.com
>> """
>>
>> Regards,
>>
>> Stephane
>>
>>
>> On 05/28/2010 06:09 PM, Dan Jacob wrote:
>>> I'll have a look at Lamson (actually looking at it already, for an
>>> unrelated work project).
>>>
>>> The message object should allow for easy handling of HTML and plain
>>> text messages:
>>>
>>> message = Message(...)
>>> message.plain = "hello"
>>> message.html = "<html>hello</html>"
>>> message.send()
>>>
>>> Attachments should be easy as well; something like:
>>>
>>> message.attach(fp, mimetype)
>>>
>>> Any thoughts on this ?
>>>
>>> On 28 May 2010 17:02, Armin Ronacher <armin.ronacher@active-4.com> wrote:
>>>> Hi,
>>>>
>>>> On 5/28/10 5:57 PM, Dan Jacob wrote:
>>>>> Lamson, as I understand it, is more of a complete framework - perhaps
>>>>> overkill if all you need is a few sendmail-type operations.
>>>> In terms of complexity turbomail is probably more a framework than
>>>> lamson is.
>>>>
>>>>> If there are some functions available from lamson that can be used
>>>>> separately of that framework however that might be an option.
>>>> As far as I know lamson has a utility module with all kinds of lower
>>>> level mail operations.  And you can also use it to start an SMTP server
>>>> locally for development usage which rocks.  So lamson > turbomail for me.
>>>>
>>>>> OK.  Probably the way to go is something from standard lib (i.e. email
>>>>> and smtplib) - the mail package in Django is a possible starting point
>>>>> in terms of what functionality to cover.
>>>> I would try lamson first though.  If that does not work good enough,
>>>> steal individual functions from there and base it on that + smtplib.
>>>>
>>>>
>>>> Regards,
>>>> Armin
>>>>
>>
>>

Re: [flask] Mail Flask extension

From:
Dan Jacob
Date:
2010-05-28 @ 16:47
 A 5 minute look at Lamson shows there are two classes at least that
might handle most of the work:

server.Relay - handles the SMTP send stuff
mail.MailResponse - the actual email message

MailResponse has functionality for encoding, multipart emails,
attachments etc, and we can use the Relay class for the low-level
sending operations.

The question is how to design the API around these classes - they are
pretty well designed so there is no reason not to be able to expose
them directly, once configured through Flask.

Something like this (very rough code):

app = Flask(__name__)
init_mail(app, Relay(....))

you can then do:

app.mail_relay.send(subj, to_, from_)
app.mail_relay.deliver(msg)

The relay object could also be added to a LocalProxy.

Anyway I'll look more closely at Lamson over the weekend and put
something up on Bitbucket at some point. In the meantime, any more
suggestions welcome.

On 28 May 2010 17:29, Stephane Wirtel <stephane@wirtel.be> wrote:
> ok, it's an example because in the case of OpenERP, we use the 
BeautifulSoup library to convert the html to txt for the mailgateway.
>
> Regards,
>
> Stephane
> On 05/28/2010 06:24 PM, Dan Jacob wrote:
>> It would be better to manage the plain and html content separately.
>>
>> On 28 May 2010 17:21, Stephane Wirtel <stephane@wirtel.be> wrote:
>>> You can use a html2plain function to convert the html string to a plain text ?
>>>
>>> """
>>> <h1>Title</h1>
>>> Hello,
>>>
>>> How are you ?
>>>
>>> <a href="http://example.com">Example.com</a>
>>> </html>
>>> """
>>>
>>> The result should be:
>>>
>>> """
>>> Title
>>> =====
>>>
>>> Hello,
>>>
>>> How are you ?
>>>
>>> Example.com [1]
>>>
>>> Links:
>>> [1] http://example.com
>>> """
>>>
>>> Regards,
>>>
>>> Stephane
>>>
>>>
>>> On 05/28/2010 06:09 PM, Dan Jacob wrote:
>>>> I'll have a look at Lamson (actually looking at it already, for an
>>>> unrelated work project).
>>>>
>>>> The message object should allow for easy handling of HTML and plain
>>>> text messages:
>>>>
>>>> message = Message(...)
>>>> message.plain = "hello"
>>>> message.html = "<html>hello</html>"
>>>> message.send()
>>>>
>>>> Attachments should be easy as well; something like:
>>>>
>>>> message.attach(fp, mimetype)
>>>>
>>>> Any thoughts on this ?
>>>>
>>>> On 28 May 2010 17:02, Armin Ronacher <armin.ronacher@active-4.com> wrote:
>>>>> Hi,
>>>>>
>>>>> On 5/28/10 5:57 PM, Dan Jacob wrote:
>>>>>> Lamson, as I understand it, is more of a complete framework - perhaps
>>>>>> overkill if all you need is a few sendmail-type operations.
>>>>> In terms of complexity turbomail is probably more a framework than
>>>>> lamson is.
>>>>>
>>>>>> If there are some functions available from lamson that can be used
>>>>>> separately of that framework however that might be an option.
>>>>> As far as I know lamson has a utility module with all kinds of lower
>>>>> level mail operations.  And you can also use it to start an SMTP server
>>>>> locally for development usage which rocks.  So lamson > turbomail for me.
>>>>>
>>>>>> OK.  Probably the way to go is something from standard lib (i.e. email
>>>>>> and smtplib) - the mail package in Django is a possible starting point
>>>>>> in terms of what functionality to cover.
>>>>> I would try lamson first though.  If that does not work good enough,
>>>>> steal individual functions from there and base it on that + smtplib.
>>>>>
>>>>>
>>>>> Regards,
>>>>> Armin
>>>>>
>>>
>>>
>
>

Re: [flask] Mail Flask extension

From:
Dan Jacob
Date:
2010-05-28 @ 23:22
I've created an repository on bitbucket, flask-mail:

http://bitbuckethttp://bitbucket.org/danjac/flask-mail/

The flask-mail extension uses Lamson. It's quite rough at this point
and requires documentation, but here's the basic idea:

from flask import Flask
from flaskext.mail import init_mail, relay, MailResponse

MAIL_SERVER = '....'
MAIL_USERNAME = '....'
MAIL_PASSWORD = '...'

app = Flask(__name__)
app.config.from_object(__name__)
init_mail(app) # relay now initialized, attached to app as mail_relay

@app.route("/")
def index():
    msg = MailResponse(Subject="test"
                                    To=recipients,
                                    From=from_addr)
    msg.Body = "test"
    msg.Html = "<b>test</b>"

    relay.deliver(msg)

You can create additional Relay instances if you need to, but the
relay object (a LocalProxy) is your default mail relay interface.

The MailResponse class is quite versatile - you can easily add
attachments for example - but it may require some wrapping, for
example to be able to use a default from address set in the
configuration.
On 28 May 2010 17:47, Dan Jacob <danjac354@gmail.com> wrote:
>  A 5 minute look at Lamson shows there are two classes at least that
> might handle most of the work:
>
> server.Relay - handles the SMTP send stuff
> mail.MailResponse - the actual email message
>
> MailResponse has functionality for encoding, multipart emails,
> attachments etc, and we can use the Relay class for the low-level
> sending operations.
>
> The question is how to design the API around these classes - they are
> pretty well designed so there is no reason not to be able to expose
> them directly, once configured through Flask.
>
> Something like this (very rough code):
>
> app = Flask(__name__)
> init_mail(app, Relay(....))
>
> you can then do:
>
> app.mail_relay.send(subj, to_, from_)
> app.mail_relay.deliver(msg)
>
> The relay object could also be added to a LocalProxy.
>
> Anyway I'll look more closely at Lamson over the weekend and put
> something up on Bitbucket at some point. In the meantime, any more
> suggestions welcome.
>
> On 28 May 2010 17:29, Stephane Wirtel <stephane@wirtel.be> wrote:
>> ok, it's an example because in the case of OpenERP, we use the 
BeautifulSoup library to convert the html to txt for the mailgateway.
>>
>> Regards,
>>
>> Stephane
>> On 05/28/2010 06:24 PM, Dan Jacob wrote:
>>> It would be better to manage the plain and html content separately.
>>>
>>> On 28 May 2010 17:21, Stephane Wirtel <stephane@wirtel.be> wrote:
>>>> You can use a html2plain function to convert the html string to a 
plain text ?
>>>>
>>>> """
>>>> <h1>Title</h1>
>>>> Hello,
>>>>
>>>> How are you ?
>>>>
>>>> <a href="http://example.com">Example.com</a>
>>>> </html>
>>>> """
>>>>
>>>> The result should be:
>>>>
>>>> """
>>>> Title
>>>> =====
>>>>
>>>> Hello,
>>>>
>>>> How are you ?
>>>>
>>>> Example.com [1]
>>>>
>>>> Links:
>>>> [1] http://example.com
>>>> """
>>>>
>>>> Regards,
>>>>
>>>> Stephane
>>>>
>>>>
>>>> On 05/28/2010 06:09 PM, Dan Jacob wrote:
>>>>> I'll have a look at Lamson (actually looking at it already, for an
>>>>> unrelated work project).
>>>>>
>>>>> The message object should allow for easy handling of HTML and plain
>>>>> text messages:
>>>>>
>>>>> message = Message(...)
>>>>> message.plain = "hello"
>>>>> message.html = "<html>hello</html>"
>>>>> message.send()
>>>>>
>>>>> Attachments should be easy as well; something like:
>>>>>
>>>>> message.attach(fp, mimetype)
>>>>>
>>>>> Any thoughts on this ?
>>>>>
>>>>> On 28 May 2010 17:02, Armin Ronacher <armin.ronacher@active-4.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> On 5/28/10 5:57 PM, Dan Jacob wrote:
>>>>>>> Lamson, as I understand it, is more of a complete framework - perhaps
>>>>>>> overkill if all you need is a few sendmail-type operations.
>>>>>> In terms of complexity turbomail is probably more a framework than
>>>>>> lamson is.
>>>>>>
>>>>>>> If there are some functions available from lamson that can be used
>>>>>>> separately of that framework however that might be an option.
>>>>>> As far as I know lamson has a utility module with all kinds of lower
>>>>>> level mail operations.  And you can also use it to start an SMTP server
>>>>>> locally for development usage which rocks.  So lamson > turbomail for me.
>>>>>>
>>>>>>> OK.  Probably the way to go is something from standard lib (i.e. email
>>>>>>> and smtplib) - the mail package in Django is a possible starting point
>>>>>>> in terms of what functionality to cover.
>>>>>> I would try lamson first though.  If that does not work good enough,
>>>>>> steal individual functions from there and base it on that + smtplib.
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Armin
>>>>>>
>>>>
>>>>
>>
>>
>

Re: [flask] Mail Flask extension

From:
Dan Jacob
Date:
2010-05-28 @ 23:23
Sorry, URL got mangled:

http://bitbucket.org/danjac/flask-mail/

On 29 May 2010 00:22, Dan Jacob <danjac354@gmail.com> wrote:
> I've created an repository on bitbucket, flask-mail:
>
> http://bitbuckethttp://bitbucket.org/danjac/flask-mail/
>
> The flask-mail extension uses Lamson. It's quite rough at this point
> and requires documentation, but here's the basic idea:
>
> from flask import Flask
> from flaskext.mail import init_mail, relay, MailResponse
>
> MAIL_SERVER = '....'
> MAIL_USERNAME = '....'
> MAIL_PASSWORD = '...'
>
> app = Flask(__name__)
> app.config.from_object(__name__)
> init_mail(app) # relay now initialized, attached to app as mail_relay
>
> @app.route("/")
> def index():
>    msg = MailResponse(Subject="test"
>                                    To=recipients,
>                                    From=from_addr)
>    msg.Body = "test"
>    msg.Html = "<b>test</b>"
>
>    relay.deliver(msg)
>
> You can create additional Relay instances if you need to, but the
> relay object (a LocalProxy) is your default mail relay interface.
>
> The MailResponse class is quite versatile - you can easily add
> attachments for example - but it may require some wrapping, for
> example to be able to use a default from address set in the
> configuration.
> On 28 May 2010 17:47, Dan Jacob <danjac354@gmail.com> wrote:
>>  A 5 minute look at Lamson shows there are two classes at least that
>> might handle most of the work:
>>
>> server.Relay - handles the SMTP send stuff
>> mail.MailResponse - the actual email message
>>
>> MailResponse has functionality for encoding, multipart emails,
>> attachments etc, and we can use the Relay class for the low-level
>> sending operations.
>>
>> The question is how to design the API around these classes - they are
>> pretty well designed so there is no reason not to be able to expose
>> them directly, once configured through Flask.
>>
>> Something like this (very rough code):
>>
>> app = Flask(__name__)
>> init_mail(app, Relay(....))
>>
>> you can then do:
>>
>> app.mail_relay.send(subj, to_, from_)
>> app.mail_relay.deliver(msg)
>>
>> The relay object could also be added to a LocalProxy.
>>
>> Anyway I'll look more closely at Lamson over the weekend and put
>> something up on Bitbucket at some point. In the meantime, any more
>> suggestions welcome.
>>
>> On 28 May 2010 17:29, Stephane Wirtel <stephane@wirtel.be> wrote:
>>> ok, it's an example because in the case of OpenERP, we use the 
BeautifulSoup library to convert the html to txt for the mailgateway.
>>>
>>> Regards,
>>>
>>> Stephane
>>> On 05/28/2010 06:24 PM, Dan Jacob wrote:
>>>> It would be better to manage the plain and html content separately.
>>>>
>>>> On 28 May 2010 17:21, Stephane Wirtel <stephane@wirtel.be> wrote:
>>>>> You can use a html2plain function to convert the html string to a 
plain text ?
>>>>>
>>>>> """
>>>>> <h1>Title</h1>
>>>>> Hello,
>>>>>
>>>>> How are you ?
>>>>>
>>>>> <a href="http://example.com">Example.com</a>
>>>>> </html>
>>>>> """
>>>>>
>>>>> The result should be:
>>>>>
>>>>> """
>>>>> Title
>>>>> =====
>>>>>
>>>>> Hello,
>>>>>
>>>>> How are you ?
>>>>>
>>>>> Example.com [1]
>>>>>
>>>>> Links:
>>>>> [1] http://example.com
>>>>> """
>>>>>
>>>>> Regards,
>>>>>
>>>>> Stephane
>>>>>
>>>>>
>>>>> On 05/28/2010 06:09 PM, Dan Jacob wrote:
>>>>>> I'll have a look at Lamson (actually looking at it already, for an
>>>>>> unrelated work project).
>>>>>>
>>>>>> The message object should allow for easy handling of HTML and plain
>>>>>> text messages:
>>>>>>
>>>>>> message = Message(...)
>>>>>> message.plain = "hello"
>>>>>> message.html = "<html>hello</html>"
>>>>>> message.send()
>>>>>>
>>>>>> Attachments should be easy as well; something like:
>>>>>>
>>>>>> message.attach(fp, mimetype)
>>>>>>
>>>>>> Any thoughts on this ?
>>>>>>
>>>>>> On 28 May 2010 17:02, Armin Ronacher <armin.ronacher@active-4.com> wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> On 5/28/10 5:57 PM, Dan Jacob wrote:
>>>>>>>> Lamson, as I understand it, is more of a complete framework - perhaps
>>>>>>>> overkill if all you need is a few sendmail-type operations.
>>>>>>> In terms of complexity turbomail is probably more a framework than
>>>>>>> lamson is.
>>>>>>>
>>>>>>>> If there are some functions available from lamson that can be used
>>>>>>>> separately of that framework however that might be an option.
>>>>>>> As far as I know lamson has a utility module with all kinds of lower
>>>>>>> level mail operations.  And you can also use it to start an SMTP server
>>>>>>> locally for development usage which rocks.  So lamson > turbomail for me.
>>>>>>>
>>>>>>>> OK.  Probably the way to go is something from standard lib (i.e. email
>>>>>>>> and smtplib) - the mail package in Django is a possible starting point
>>>>>>>> in terms of what functionality to cover.
>>>>>>> I would try lamson first though.  If that does not work good enough,
>>>>>>> steal individual functions from there and base it on that + smtplib.
>>>>>>>
>>>>>>>
>>>>>>> Regards,
>>>>>>> Armin
>>>>>>>
>>>>>
>>>>>
>>>
>>>
>>
>

Re: [flask] Mail Flask extension

From:
Stephane Wirtel
Date:
2010-05-29 @ 06:59
Hi Dan,

Thank you so much for your job. 

But I have a question, do you think it's possible to create a real wrapper
over Lamson, because the style of the API of Lamson (UpperCase for the 
attributes) differs from the api of Flask.

For example:

def index():
  msg = MailResponse(subject='test', to=recipients, from=from_addr)
  msg.body = "Hello"
  relay.deliver(msg)


I'm waiting for your opinion about this point.

If you want some helps, I can help you.

Regards,

Stephane

On 29 May 2010, at 01:23, Dan Jacob wrote:

> Sorry, URL got mangled:
> 
> http://bitbucket.org/danjac/flask-mail/
> 
> On 29 May 2010 00:22, Dan Jacob <danjac354@gmail.com> wrote:
>> I've created an repository on bitbucket, flask-mail:
>> 
>> http://bitbuckethttp://bitbucket.org/danjac/flask-mail/
>> 
>> The flask-mail extension uses Lamson. It's quite rough at this point
>> and requires documentation, but here's the basic idea:
>> 
>> from flask import Flask
>> from flaskext.mail import init_mail, relay, MailResponse
>> 
>> MAIL_SERVER = '....'
>> MAIL_USERNAME = '....'
>> MAIL_PASSWORD = '...'
>> 
>> app = Flask(__name__)
>> app.config.from_object(__name__)
>> init_mail(app) # relay now initialized, attached to app as mail_relay
>> 
>> @app.route("/")
>> def index():
>>    msg = MailResponse(Subject="test"
>>                                    To=recipients,
>>                                    From=from_addr)
>>    msg.Body = "test"
>>    msg.Html = "<b>test</b>"
>> 
>>    relay.deliver(msg)
>> 
>> You can create additional Relay instances if you need to, but the
>> relay object (a LocalProxy) is your default mail relay interface.
>> 
>> The MailResponse class is quite versatile - you can easily add
>> attachments for example - but it may require some wrapping, for
>> example to be able to use a default from address set in the
>> configuration.
>> On 28 May 2010 17:47, Dan Jacob <danjac354@gmail.com> wrote:
>>>  A 5 minute look at Lamson shows there are two classes at least that
>>> might handle most of the work:
>>> 
>>> server.Relay - handles the SMTP send stuff
>>> mail.MailResponse - the actual email message
>>> 
>>> MailResponse has functionality for encoding, multipart emails,
>>> attachments etc, and we can use the Relay class for the low-level
>>> sending operations.
>>> 
>>> The question is how to design the API around these classes - they are
>>> pretty well designed so there is no reason not to be able to expose
>>> them directly, once configured through Flask.
>>> 
>>> Something like this (very rough code):
>>> 
>>> app = Flask(__name__)
>>> init_mail(app, Relay(....))
>>> 
>>> you can then do:
>>> 
>>> app.mail_relay.send(subj, to_, from_)
>>> app.mail_relay.deliver(msg)
>>> 
>>> The relay object could also be added to a LocalProxy.
>>> 
>>> Anyway I'll look more closely at Lamson over the weekend and put
>>> something up on Bitbucket at some point. In the meantime, any more
>>> suggestions welcome.
>>> 
>>> On 28 May 2010 17:29, Stephane Wirtel <stephane@wirtel.be> wrote:
>>>> ok, it's an example because in the case of OpenERP, we use the 
BeautifulSoup library to convert the html to txt for the mailgateway.
>>>> 
>>>> Regards,
>>>> 
>>>> Stephane
>>>> On 05/28/2010 06:24 PM, Dan Jacob wrote:
>>>>> It would be better to manage the plain and html content separately.
>>>>> 
>>>>> On 28 May 2010 17:21, Stephane Wirtel <stephane@wirtel.be> wrote:
>>>>>> You can use a html2plain function to convert the html string to a 
plain text ?
>>>>>> 
>>>>>> """
>>>>>> <h1>Title</h1>
>>>>>> Hello,
>>>>>> 
>>>>>> How are you ?
>>>>>> 
>>>>>> <a href="http://example.com">Example.com</a>
>>>>>> </html>
>>>>>> """
>>>>>> 
>>>>>> The result should be:
>>>>>> 
>>>>>> """
>>>>>> Title
>>>>>> =====
>>>>>> 
>>>>>> Hello,
>>>>>> 
>>>>>> How are you ?
>>>>>> 
>>>>>> Example.com [1]
>>>>>> 
>>>>>> Links:
>>>>>> [1] http://example.com
>>>>>> """
>>>>>> 
>>>>>> Regards,
>>>>>> 
>>>>>> Stephane
>>>>>> 
>>>>>> 
>>>>>> On 05/28/2010 06:09 PM, Dan Jacob wrote:
>>>>>>> I'll have a look at Lamson (actually looking at it already, for an
>>>>>>> unrelated work project).
>>>>>>> 
>>>>>>> The message object should allow for easy handling of HTML and plain
>>>>>>> text messages:
>>>>>>> 
>>>>>>> message = Message(...)
>>>>>>> message.plain = "hello"
>>>>>>> message.html = "<html>hello</html>"
>>>>>>> message.send()
>>>>>>> 
>>>>>>> Attachments should be easy as well; something like:
>>>>>>> 
>>>>>>> message.attach(fp, mimetype)
>>>>>>> 
>>>>>>> Any thoughts on this ?
>>>>>>> 
>>>>>>> On 28 May 2010 17:02, Armin Ronacher <armin.ronacher@active-4.com> wrote:
>>>>>>>> Hi,
>>>>>>>> 
>>>>>>>> On 5/28/10 5:57 PM, Dan Jacob wrote:
>>>>>>>>> Lamson, as I understand it, is more of a complete framework - perhaps
>>>>>>>>> overkill if all you need is a few sendmail-type operations.
>>>>>>>> In terms of complexity turbomail is probably more a framework than
>>>>>>>> lamson is.
>>>>>>>> 
>>>>>>>>> If there are some functions available from lamson that can be used
>>>>>>>>> separately of that framework however that might be an option.
>>>>>>>> As far as I know lamson has a utility module with all kinds of lower
>>>>>>>> level mail operations.  And you can also use it to start an SMTP server
>>>>>>>> locally for development usage which rocks.  So lamson > turbomail for me.
>>>>>>>> 
>>>>>>>>> OK.  Probably the way to go is something from standard lib (i.e. email
>>>>>>>>> and smtplib) - the mail package in Django is a possible starting point
>>>>>>>>> in terms of what functionality to cover.
>>>>>>>> I would try lamson first though.  If that does not work good enough,
>>>>>>>> steal individual functions from there and base it on that + smtplib.
>>>>>>>> 
>>>>>>>> 
>>>>>>>> Regards,
>>>>>>>> Armin
>>>>>>>> 
>>>>>> 
>>>>>> 
>>>> 
>>>> 
>>> 
>> 

Re: [flask] Mail Flask extension

From:
Dan Jacob
Date:
2010-05-29 @ 07:07
Yes, I was considering this point - although I think the reason for
the upper case for the attributes was because "To" and "From" are
Python keywords, and it was just to be consistent  - "sender" and
"recipients" would work just as well.

The main reason I'd like to wrap MailResponse however is so that you
can set a DEFAULT_MAIL_SENDER in your configuration, e.g.
"support@mysite.com". It would also be possible to add further
convenience methods e.g. add_recipient.

"MailResponse" also makes sense in a Lamson context, but could be
confusing for people who don't know Lamson - "Message" works better.

I'm also thinking about having the Relay instance wrapped in the
Message object. Therefore instead of this:

msg  = Message(....)
relay.deliver(msg)

You can just do this:

msg.send()

However, if you want to use another Relay instance you can:

relay = Relay(....)
msg.send(relay)


On 29 May 2010 07:59, Stephane Wirtel <stephane@wirtel.be> wrote:
> Hi Dan,
>
> Thank you so much for your job.
>
> But I have a question, do you think it's possible to create a real 
wrapper over Lamson, because the style of the API of Lamson (UpperCase for
the attributes) differs from the api of Flask.
>
> For example:
>
> def index():
>  msg = MailResponse(subject='test', to=recipients, from=from_addr)
>  msg.body = "Hello"
>  relay.deliver(msg)
>
>
> I'm waiting for your opinion about this point.
>
> If you want some helps, I can help you.
>
> Regards,
>
> Stephane
>
> On 29 May 2010, at 01:23, Dan Jacob wrote:
>
>> Sorry, URL got mangled:
>>
>> http://bitbucket.org/danjac/flask-mail/
>>
>> On 29 May 2010 00:22, Dan Jacob <danjac354@gmail.com> wrote:
>>> I've created an repository on bitbucket, flask-mail:
>>>
>>> http://bitbuckethttp://bitbucket.org/danjac/flask-mail/
>>>
>>> The flask-mail extension uses Lamson. It's quite rough at this point
>>> and requires documentation, but here's the basic idea:
>>>
>>> from flask import Flask
>>> from flaskext.mail import init_mail, relay, MailResponse
>>>
>>> MAIL_SERVER = '....'
>>> MAIL_USERNAME = '....'
>>> MAIL_PASSWORD = '...'
>>>
>>> app = Flask(__name__)
>>> app.config.from_object(__name__)
>>> init_mail(app) # relay now initialized, attached to app as mail_relay
>>>
>>> @app.route("/")
>>> def index():
>>>    msg = MailResponse(Subject="test"
>>>                                    To=recipients,
>>>                                    From=from_addr)
>>>    msg.Body = "test"
>>>    msg.Html = "<b>test</b>"
>>>
>>>    relay.deliver(msg)
>>>
>>> You can create additional Relay instances if you need to, but the
>>> relay object (a LocalProxy) is your default mail relay interface.
>>>
>>> The MailResponse class is quite versatile - you can easily add
>>> attachments for example - but it may require some wrapping, for
>>> example to be able to use a default from address set in the
>>> configuration.
>>> On 28 May 2010 17:47, Dan Jacob <danjac354@gmail.com> wrote:
>>>>  A 5 minute look at Lamson shows there are two classes at least that
>>>> might handle most of the work:
>>>>
>>>> server.Relay - handles the SMTP send stuff
>>>> mail.MailResponse - the actual email message
>>>>
>>>> MailResponse has functionality for encoding, multipart emails,
>>>> attachments etc, and we can use the Relay class for the low-level
>>>> sending operations.
>>>>
>>>> The question is how to design the API around these classes - they are
>>>> pretty well designed so there is no reason not to be able to expose
>>>> them directly, once configured through Flask.
>>>>
>>>> Something like this (very rough code):
>>>>
>>>> app = Flask(__name__)
>>>> init_mail(app, Relay(....))
>>>>
>>>> you can then do:
>>>>
>>>> app.mail_relay.send(subj, to_, from_)
>>>> app.mail_relay.deliver(msg)
>>>>
>>>> The relay object could also be added to a LocalProxy.
>>>>
>>>> Anyway I'll look more closely at Lamson over the weekend and put
>>>> something up on Bitbucket at some point. In the meantime, any more
>>>> suggestions welcome.
>>>>
>>>> On 28 May 2010 17:29, Stephane Wirtel <stephane@wirtel.be> wrote:
>>>>> ok, it's an example because in the case of OpenERP, we use the 
BeautifulSoup library to convert the html to txt for the mailgateway.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Stephane
>>>>> On 05/28/2010 06:24 PM, Dan Jacob wrote:
>>>>>> It would be better to manage the plain and html content separately.
>>>>>>
>>>>>> On 28 May 2010 17:21, Stephane Wirtel <stephane@wirtel.be> wrote:
>>>>>>> You can use a html2plain function to convert the html string to a 
plain text ?
>>>>>>>
>>>>>>> """
>>>>>>> <h1>Title</h1>
>>>>>>> Hello,
>>>>>>>
>>>>>>> How are you ?
>>>>>>>
>>>>>>> <a href="http://example.com">Example.com</a>
>>>>>>> </html>
>>>>>>> """
>>>>>>>
>>>>>>> The result should be:
>>>>>>>
>>>>>>> """
>>>>>>> Title
>>>>>>> =====
>>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> How are you ?
>>>>>>>
>>>>>>> Example.com [1]
>>>>>>>
>>>>>>> Links:
>>>>>>> [1] http://example.com
>>>>>>> """
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Stephane
>>>>>>>
>>>>>>>
>>>>>>> On 05/28/2010 06:09 PM, Dan Jacob wrote:
>>>>>>>> I'll have a look at Lamson (actually looking at it already, for an
>>>>>>>> unrelated work project).
>>>>>>>>
>>>>>>>> The message object should allow for easy handling of HTML and plain
>>>>>>>> text messages:
>>>>>>>>
>>>>>>>> message = Message(...)
>>>>>>>> message.plain = "hello"
>>>>>>>> message.html = "<html>hello</html>"
>>>>>>>> message.send()
>>>>>>>>
>>>>>>>> Attachments should be easy as well; something like:
>>>>>>>>
>>>>>>>> message.attach(fp, mimetype)
>>>>>>>>
>>>>>>>> Any thoughts on this ?
>>>>>>>>
>>>>>>>> On 28 May 2010 17:02, Armin Ronacher <armin.ronacher@active-4.com> wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> On 5/28/10 5:57 PM, Dan Jacob wrote:
>>>>>>>>>> Lamson, as I understand it, is more of a complete framework - perhaps
>>>>>>>>>> overkill if all you need is a few sendmail-type operations.
>>>>>>>>> In terms of complexity turbomail is probably more a framework than
>>>>>>>>> lamson is.
>>>>>>>>>
>>>>>>>>>> If there are some functions available from lamson that can be used
>>>>>>>>>> separately of that framework however that might be an option.
>>>>>>>>> As far as I know lamson has a utility module with all kinds of lower
>>>>>>>>> level mail operations.  And you can also use it to start an SMTP server
>>>>>>>>> locally for development usage which rocks.  So lamson > 
turbomail for me.
>>>>>>>>>
>>>>>>>>>> OK.  Probably the way to go is something from standard lib (i.e. email
>>>>>>>>>> and smtplib) - the mail package in Django is a possible starting point
>>>>>>>>>> in terms of what functionality to cover.
>>>>>>>>> I would try lamson first though.  If that does not work good enough,
>>>>>>>>> steal individual functions from there and base it on that + smtplib.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>> Armin
>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>
>>>
>
>

Re: [flask] Mail Flask extension

From:
Dan Jacob
Date:
2010-05-29 @ 07:14
Another issue is being able to set logging configuration easily, as
Lamson has its own logging setup.

On 29 May 2010 08:07, Dan Jacob <danjac354@gmail.com> wrote:
> Yes, I was considering this point - although I think the reason for
> the upper case for the attributes was because "To" and "From" are
> Python keywords, and it was just to be consistent  - "sender" and
> "recipients" would work just as well.
>
> The main reason I'd like to wrap MailResponse however is so that you
> can set a DEFAULT_MAIL_SENDER in your configuration, e.g.
> "support@mysite.com". It would also be possible to add further
> convenience methods e.g. add_recipient.
>
> "MailResponse" also makes sense in a Lamson context, but could be
> confusing for people who don't know Lamson - "Message" works better.
>
> I'm also thinking about having the Relay instance wrapped in the
> Message object. Therefore instead of this:
>
> msg  = Message(....)
> relay.deliver(msg)
>
> You can just do this:
>
> msg.send()
>
> However, if you want to use another Relay instance you can:
>
> relay = Relay(....)
> msg.send(relay)
>
>
> On 29 May 2010 07:59, Stephane Wirtel <stephane@wirtel.be> wrote:
>> Hi Dan,
>>
>> Thank you so much for your job.
>>
>> But I have a question, do you think it's possible to create a real 
wrapper over Lamson, because the style of the API of Lamson (UpperCase for
the attributes) differs from the api of Flask.
>>
>> For example:
>>
>> def index():
>>  msg = MailResponse(subject='test', to=recipients, from=from_addr)
>>  msg.body = "Hello"
>>  relay.deliver(msg)
>>
>>
>> I'm waiting for your opinion about this point.
>>
>> If you want some helps, I can help you.
>>
>> Regards,
>>
>> Stephane
>>
>> On 29 May 2010, at 01:23, Dan Jacob wrote:
>>
>>> Sorry, URL got mangled:
>>>
>>> http://bitbucket.org/danjac/flask-mail/
>>>
>>> On 29 May 2010 00:22, Dan Jacob <danjac354@gmail.com> wrote:
>>>> I've created an repository on bitbucket, flask-mail:
>>>>
>>>> http://bitbuckethttp://bitbucket.org/danjac/flask-mail/
>>>>
>>>> The flask-mail extension uses Lamson. It's quite rough at this point
>>>> and requires documentation, but here's the basic idea:
>>>>
>>>> from flask import Flask
>>>> from flaskext.mail import init_mail, relay, MailResponse
>>>>
>>>> MAIL_SERVER = '....'
>>>> MAIL_USERNAME = '....'
>>>> MAIL_PASSWORD = '...'
>>>>
>>>> app = Flask(__name__)
>>>> app.config.from_object(__name__)
>>>> init_mail(app) # relay now initialized, attached to app as mail_relay
>>>>
>>>> @app.route("/")
>>>> def index():
>>>>    msg = MailResponse(Subject="test"
>>>>                                    To=recipients,
>>>>                                    From=from_addr)
>>>>    msg.Body = "test"
>>>>    msg.Html = "<b>test</b>"
>>>>
>>>>    relay.deliver(msg)
>>>>
>>>> You can create additional Relay instances if you need to, but the
>>>> relay object (a LocalProxy) is your default mail relay interface.
>>>>
>>>> The MailResponse class is quite versatile - you can easily add
>>>> attachments for example - but it may require some wrapping, for
>>>> example to be able to use a default from address set in the
>>>> configuration.
>>>> On 28 May 2010 17:47, Dan Jacob <danjac354@gmail.com> wrote:
>>>>>  A 5 minute look at Lamson shows there are two classes at least that
>>>>> might handle most of the work:
>>>>>
>>>>> server.Relay - handles the SMTP send stuff
>>>>> mail.MailResponse - the actual email message
>>>>>
>>>>> MailResponse has functionality for encoding, multipart emails,
>>>>> attachments etc, and we can use the Relay class for the low-level
>>>>> sending operations.
>>>>>
>>>>> The question is how to design the API around these classes - they are
>>>>> pretty well designed so there is no reason not to be able to expose
>>>>> them directly, once configured through Flask.
>>>>>
>>>>> Something like this (very rough code):
>>>>>
>>>>> app = Flask(__name__)
>>>>> init_mail(app, Relay(....))
>>>>>
>>>>> you can then do:
>>>>>
>>>>> app.mail_relay.send(subj, to_, from_)
>>>>> app.mail_relay.deliver(msg)
>>>>>
>>>>> The relay object could also be added to a LocalProxy.
>>>>>
>>>>> Anyway I'll look more closely at Lamson over the weekend and put
>>>>> something up on Bitbucket at some point. In the meantime, any more
>>>>> suggestions welcome.
>>>>>
>>>>> On 28 May 2010 17:29, Stephane Wirtel <stephane@wirtel.be> wrote:
>>>>>> ok, it's an example because in the case of OpenERP, we use the 
BeautifulSoup library to convert the html to txt for the mailgateway.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Stephane
>>>>>> On 05/28/2010 06:24 PM, Dan Jacob wrote:
>>>>>>> It would be better to manage the plain and html content separately.
>>>>>>>
>>>>>>> On 28 May 2010 17:21, Stephane Wirtel <stephane@wirtel.be> wrote:
>>>>>>>> You can use a html2plain function to convert the html string to a
plain text ?
>>>>>>>>
>>>>>>>> """
>>>>>>>> <h1>Title</h1>
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> How are you ?
>>>>>>>>
>>>>>>>> <a href="http://example.com">Example.com</a>
>>>>>>>> </html>
>>>>>>>> """
>>>>>>>>
>>>>>>>> The result should be:
>>>>>>>>
>>>>>>>> """
>>>>>>>> Title
>>>>>>>> =====
>>>>>>>>
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> How are you ?
>>>>>>>>
>>>>>>>> Example.com [1]
>>>>>>>>
>>>>>>>> Links:
>>>>>>>> [1] http://example.com
>>>>>>>> """
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> Stephane
>>>>>>>>
>>>>>>>>
>>>>>>>> On 05/28/2010 06:09 PM, Dan Jacob wrote:
>>>>>>>>> I'll have a look at Lamson (actually looking at it already, for an
>>>>>>>>> unrelated work project).
>>>>>>>>>
>>>>>>>>> The message object should allow for easy handling of HTML and plain
>>>>>>>>> text messages:
>>>>>>>>>
>>>>>>>>> message = Message(...)
>>>>>>>>> message.plain = "hello"
>>>>>>>>> message.html = "<html>hello</html>"
>>>>>>>>> message.send()
>>>>>>>>>
>>>>>>>>> Attachments should be easy as well; something like:
>>>>>>>>>
>>>>>>>>> message.attach(fp, mimetype)
>>>>>>>>>
>>>>>>>>> Any thoughts on this ?
>>>>>>>>>
>>>>>>>>> On 28 May 2010 17:02, Armin Ronacher 
<armin.ronacher@active-4.com> wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> On 5/28/10 5:57 PM, Dan Jacob wrote:
>>>>>>>>>>> Lamson, as I understand it, is more of a complete framework - perhaps
>>>>>>>>>>> overkill if all you need is a few sendmail-type operations.
>>>>>>>>>> In terms of complexity turbomail is probably more a framework than
>>>>>>>>>> lamson is.
>>>>>>>>>>
>>>>>>>>>>> If there are some functions available from lamson that can be used
>>>>>>>>>>> separately of that framework however that might be an option.
>>>>>>>>>> As far as I know lamson has a utility module with all kinds of lower
>>>>>>>>>> level mail operations.  And you can also use it to start an SMTP server
>>>>>>>>>> locally for development usage which rocks.  So lamson > 
turbomail for me.
>>>>>>>>>>
>>>>>>>>>>> OK.  Probably the way to go is something from standard lib (i.e. email
>>>>>>>>>>> and smtplib) - the mail package in Django is a possible starting point
>>>>>>>>>>> in terms of what functionality to cover.
>>>>>>>>>> I would try lamson first though.  If that does not work good enough,
>>>>>>>>>> steal individual functions from there and base it on that + smtplib.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>> Armin
>>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>
>>
>

Re: [flask] Mail Flask extension

From:
Armin Ronacher
Date:
2010-05-28 @ 16:23
On 2010-05-28 6:21 PM, Stephane Wirtel wrote:
> You can use a html2plain function to convert the html string to a plain text ?
That's what Zine is doing with ZEML.  Hugely complex but possible.  But 
before that ends up in a flask extension that html to text conversion 
should be refactored from Zine into a separate Python library that does 
that.


Regards,
Armin

Re: [flask] Mail Flask extension

From:
Dan Jacob
Date:
2010-05-28 @ 16:26
BeautifulSoup can be used as well at a pinch, but this is outside the
context of mail handling.

On 28 May 2010 17:23, Armin Ronacher <armin.ronacher@active-4.com> wrote:
> On 2010-05-28 6:21 PM, Stephane Wirtel wrote:
>> You can use a html2plain function to convert the html string to a plain text ?
> That's what Zine is doing with ZEML.  Hugely complex but possible.  But
> before that tends up in a flask extension that html to text conversion
> should be refactored from Zine into a separate Python library that does
> that.
>
>
> Regards,
> Armin
>

Re: [flask] Mail Flask extension

From:
Armin Ronacher
Date:
2010-05-28 @ 16:20
Hi,

On 2010-05-28 6:09 PM, Dan Jacob wrote:
> The message object should allow for easy handling of HTML and plain
> text messages:
>
> message = Message(...)
> message.plain = "hello"
> message.html = "<html>hello</html>"
> message.send()
>
> Attachments should be easy as well; something like:
>
> message.attach(fp, mimetype)
>
> Any thoughts on this ?
Better something like that:

message.add_part('hello', 'text/plain')
message.add_part('<p><strong>Hello</strong>', 'text/html')

And then you can still add easier methods like message.add_html / 
message.add_text that calls into add_part.


Regards,
Armin

Re: [flask] Mail Flask extension

From:
Armin Ronacher
Date:
2010-05-28 @ 16:00
A good API in general would be something like this:

   from flask import Flask
   from flaskext.mail import init_mail

   MAIL_SERVER = 'localhost'
   DEFAULT_MAIL_FROM = 'no-reply@example.com'

   app = Flask(__name__)
   app.config.from_object(__name__)
   init_mail(app)

To send mails you can then do something like this:

   from flaskext.mail import Message

   mail = Message('Hello World', 'This is the body')
   mail.add_recipient('foo@example.com')
   mail.send()

Not sure about the actual Message object.  What init_mail does is 
attaching a default deliver interface to the flask app object so that it 
can be used as mail.send() default.  However there should also be a 
method to create another mail interface and explicitly pass that to send:

   from flaskext.mail import MailInterface
   interface = MailInterface(...)

Why?  Because you will need more than one.  The following for example:

   SMTPInterface(...) to send mail to an SMTP server
   TestInterface(...) a mail interface that stores the mails in memory
                      for unittesting.

Also you might want to have multiple SMTP interfaces.  For example 
premium users might have a faster SMTP server for mail delivery or you 
just want more for load balancing.


Regards,
Armin