For sending emails from your Flask application: http://packages.python.org/flask-mail/ Thanks to Armin and others on this mailing list who provided input and feedback.
Hi,
I just stumbled upon a bug: You are using a mutable as default
parameter in the Message constructor. This causes troubles:
>>> def foo(a=[]):
... a.append(len(a))
... return a
...
>>> foo()
[0]
>>> foo()
[0, 1]
>>> foo()
[0, 1, 2]
>>> foo()
[0, 1, 2, 3]
Better declare it as None and check for None in the constructor:
def __init__(self, recipients=None, ...):
if recipients is None:
recipients = []
self.recipients = recipients
Regards,
Armin
Thanks, will fix. On 1 June 2010 08:35, Armin Ronacher <armin.ronacher@active-4.com> wrote: > Hi, > > I just stumbled upon a bug: You are using a mutable as default > parameter in the Message constructor. This causes troubles: > > >>> def foo(a=[]): > ... a.append(len(a)) > ... return a > ... > >>> foo() > [0] > >>> foo() > [0, 1] > >>> foo() > [0, 1, 2] > >>> foo() > [0, 1, 2, 3] > > Better declare it as None and check for None in the constructor: > > def __init__(self, recipients=None, ...): > if recipients is None: > recipients = [] > self.recipients = recipients > > > > Regards, > Armin >
A bit off-topic: what's the protocol with bugfixes and PyPi packages ? Is it OK to just replace the current version (e.g. 0.1) files if you want to release a fix, or better to release a new package (e.g. 0.2) ? On 1 June 2010 08:37, Dan Jacob <danjac354@gmail.com> wrote: > Thanks, will fix. > > On 1 June 2010 08:35, Armin Ronacher <armin.ronacher@active-4.com> wrote: >> Hi, >> >> I just stumbled upon a bug: You are using a mutable as default >> parameter in the Message constructor. This causes troubles: >> >> >>> def foo(a=[]): >> ... a.append(len(a)) >> ... return a >> ... >> >>> foo() >> [0] >> >>> foo() >> [0, 1] >> >>> foo() >> [0, 1, 2] >> >>> foo() >> [0, 1, 2, 3] >> >> Better declare it as None and check for None in the constructor: >> >> def __init__(self, recipients=None, ...): >> if recipients is None: >> recipients = [] >> self.recipients = recipients >> >> >> >> Regards, >> Armin >> >
Hi, On 6/1/10 10:10 AM, Dan Jacob wrote: > A bit off-topic: what's the protocol with bugfixes and PyPi packages ? > Is it OK to just replace the current version (e.g. 0.1) files if you > want to release a fix, or better to release a new package (e.g. 0.2) ? Piotr Ozarowski will shoot you if you do that. Upload a 0.2 or 0.1.1 instead. Regards, Armin
Glad I asked :-) On 1 June 2010 09:23, Armin Ronacher <armin.ronacher@active-4.com> wrote: > Hi, > > On 6/1/10 10:10 AM, Dan Jacob wrote: >> A bit off-topic: what's the protocol with bugfixes and PyPi packages ? >> Is it OK to just replace the current version (e.g. 0.1) files if you >> want to release a fix, or better to release a new package (e.g. 0.2) ? > Piotr Ozarowski will shoot you if you do that. Upload a 0.2 or 0.1.1 > instead. > > > Regards, > Armin >
Hi, On 2010-06-01 12:24 AM, Dan Jacob wrote: > For sending emails from your Flask application: > http://packages.python.org/flask-mail/ Nice. I added it to the page. If you don't mind I would love to propose a slightly modified version of the logo though with the High Tower Text Flask Type for the Logo :) If you like I can modify it for you. Regards, Armin
> Nice. I added it to the page. If you don't mind I would love to > propose a slightly modified version of the logo though with the High > Tower Text Flask Type for the Logo :) If you like I can modify it for you. I suggest a message in a bottle as the logo.
Django mail supports header injection protection: http://docs.djangoproject.com/en/dev/topics/email/#preventing-header-injection Basically, this just checks for newlines in subject/sender/recipients and raises an error if found. Probably a good idea to add this to flask-mail just in case.
On 2010-06-01 3:41 PM, Dan Jacob wrote:
> Probably a good idea to add this to flask-mail just in case.
Yes. If Lamson does not doe that on its own, make sure you do.
Regards,
Armin
I've added header injection support to flask-mail - if Lamson does prevent mutliline headers, I was unable to find reference to it in the source or documentation. This has been added to latest version (0.1.2) so please update to this more secure version. On 1 June 2010 15:00, Armin Ronacher <armin.ronacher@active-4.com> wrote: > On 2010-06-01 3:41 PM, Dan Jacob wrote: >> Probably a good idea to add this to flask-mail just in case. > Yes. If Lamson does not doe that on its own, make sure you do. > > > Regards, > Armin >
> I've added header injection support to flask-mail - if Lamson does > prevent mutliline headers, I was unable to find reference to it in the > source or documentation. Maybe someone should talk to Zed about adding it to Lamson if it's not already there?
Hi, On 6/1/10 4:27 PM, Dag Odenhall wrote: > Maybe someone should talk to Zed about adding it to Lamson if it's not > already there? Huge +1 on that. Regards, Armin
If it is there, then I'd rather use what's already been done than reinvent the wheel. I've posted the question on the Lamson mailing list. On 1 June 2010 15:29, Armin Ronacher <armin.ronacher@active-4.com> wrote: > Hi, > > > On 6/1/10 4:27 PM, Dag Odenhall wrote: >> Maybe someone should talk to Zed about adding it to Lamson if it's not >> already there? > Huge +1 on that. > > > Regards, > Armin >
I was going to ask you what font you used, thanks :-) On 1 June 2010 00:46, Armin Ronacher <armin.ronacher@active-4.com> wrote: > Hi, > > On 2010-06-01 12:24 AM, Dan Jacob wrote: >> For sending emails from your Flask application: >> http://packages.python.org/flask-mail/ > Nice. I added it to the page. If you don't mind I would love to > propose a slightly modified version of the logo though with the High > Tower Text Flask Type for the Logo :) If you like I can modify it for you. > > Regards, > Armin >
On 2010-06-01 7:56 AM, Dan Jacob wrote:
> I was going to ask you what font you used, thanks :-)
Here a very with line-art for the logo. Feel free to copy the existing
picture over if you don't like it.
http://dev.pocoo.org/~mitsuhiko/flask-mail.png
Regards,
Armin
Hi, On 2010-06-01 8:33 AM, Armin Ronacher wrote: > Here a very with line-art for the logo. Feel free to copy the existing > picture over if you don't like it. Grammar fail. Should have been "very simple version" I suppose. Anyways. Here an alternative proposal with a message in a bottle as proposed on #pocoo or somewhere in that mailinglist. http://dev.pocoo.org/~mitsuhiko/flask-mail.png Regards, Armin
Question: If I need to send a batch of emails, does flask-mail open a new SMTP connection for each msg.send() or is there a way to open a connection, send my batch of emails (roughly 5000) and then close the connection? Currently I am just using smtplib to perform this operation. -- Thadeus On Tue, Jun 1, 2010 at 5:20 PM, Armin Ronacher <armin.ronacher@active-4.com> wrote: > Hi, > > On 2010-06-01 8:33 AM, Armin Ronacher wrote: >> Here a very with line-art for the logo. Feel free to copy the existing >> picture over if you don't like it. > Grammar fail. Should have been "very simple version" I suppose. > > Anyways. Here an alternative proposal with a message in a bottle as > proposed on #pocoo or somewhere in that mailinglist. > > http://dev.pocoo.org/~mitsuhiko/flask-mail.png > > > Regards, > Armin >
The connection is created and wrapped in a Lamson Relay instance which is monkeypatched to the application as mail_relay. You can also use a different relay instance if you want to. The same connection is therefore re-used across all messages when you call send(). That said, I'd be interested in seeing how efficient it is to use flask-mail for high volume message batches, although that sounds like something that should be done outside the web process in any case. On 9 June 2010 14:51, Thadeus Burgess <thadeusb@thadeusb.com> wrote: > Question: > > If I need to send a batch of emails, does flask-mail open a new SMTP > connection for each msg.send() or is there a way to open a connection, > send my batch of emails (roughly 5000) and then close the connection? > Currently I am just using smtplib to perform this operation. > > -- > Thadeus > > > > > > On Tue, Jun 1, 2010 at 5:20 PM, Armin Ronacher > <armin.ronacher@active-4.com> wrote: >> Hi, >> >> On 2010-06-01 8:33 AM, Armin Ronacher wrote: >>> Here a very with line-art for the logo. Feel free to copy the existing >>> picture over if you don't like it. >> Grammar fail. Should have been "very simple version" I suppose. >> >> Anyways. Here an alternative proposal with a message in a bottle as >> proposed on #pocoo or somewhere in that mailinglist. >> >> http://dev.pocoo.org/~mitsuhiko/flask-mail.png >> >> >> Regards, >> Armin >> >
Having looked at the source code, it appears that the Relay instance actually creates the connection before each send(). However in the case of sending 5000 mails, you just pass in your 5000 mail addresses to the Message.recipients, and they will be sent under the same connection. If however you require sending a slightly different Message instance to 5000 recipients, perhaps we can look at adding some bulk send functionality that reuses the same connection. On 9 June 2010 23:54, Dan Jacob <danjac354@gmail.com> wrote: > The connection is created and wrapped in a Lamson Relay instance which > is monkeypatched to the application as mail_relay. > > You can also use a different relay instance if you want to. > > The same connection is therefore re-used across all messages when you > call send(). > > That said, I'd be interested in seeing how efficient it is to use > flask-mail for high volume message batches, although that sounds like > something that should be done outside the web process in any case. > > On 9 June 2010 14:51, Thadeus Burgess <thadeusb@thadeusb.com> wrote: >> Question: >> >> If I need to send a batch of emails, does flask-mail open a new SMTP >> connection for each msg.send() or is there a way to open a connection, >> send my batch of emails (roughly 5000) and then close the connection? >> Currently I am just using smtplib to perform this operation. >> >> -- >> Thadeus >> >> >> >> >> >> On Tue, Jun 1, 2010 at 5:20 PM, Armin Ronacher >> <armin.ronacher@active-4.com> wrote: >>> Hi, >>> >>> On 2010-06-01 8:33 AM, Armin Ronacher wrote: >>>> Here a very with line-art for the logo. Feel free to copy the existing >>>> picture over if you don't like it. >>> Grammar fail. Should have been "very simple version" I suppose. >>> >>> Anyways. Here an alternative proposal with a message in a bottle as >>> proposed on #pocoo or somewhere in that mailinglist. >>> >>> http://dev.pocoo.org/~mitsuhiko/flask-mail.png >>> >>> >>> Regards, >>> Armin >>> >> >
I've added bulk send functionality to the flask-mail repository, once fully tested it will be in next release. On 10 June 2010 07:16, Dan Jacob <danjac354@gmail.com> wrote: > Having looked at the source code, it appears that the Relay instance > actually creates the connection before each send(). > > However in the case of sending 5000 mails, you just pass in your 5000 > mail addresses to the Message.recipients, and they will be sent under > the same connection. > > If however you require sending a slightly different Message instance > to 5000 recipients, perhaps we can look at adding some bulk send > functionality that reuses the same connection. > > On 9 June 2010 23:54, Dan Jacob <danjac354@gmail.com> wrote: >> The connection is created and wrapped in a Lamson Relay instance which >> is monkeypatched to the application as mail_relay. >> >> You can also use a different relay instance if you want to. >> >> The same connection is therefore re-used across all messages when you >> call send(). >> >> That said, I'd be interested in seeing how efficient it is to use >> flask-mail for high volume message batches, although that sounds like >> something that should be done outside the web process in any case. >> >> On 9 June 2010 14:51, Thadeus Burgess <thadeusb@thadeusb.com> wrote: >>> Question: >>> >>> If I need to send a batch of emails, does flask-mail open a new SMTP >>> connection for each msg.send() or is there a way to open a connection, >>> send my batch of emails (roughly 5000) and then close the connection? >>> Currently I am just using smtplib to perform this operation. >>> >>> -- >>> Thadeus >>> >>> >>> >>> >>> >>> On Tue, Jun 1, 2010 at 5:20 PM, Armin Ronacher >>> <armin.ronacher@active-4.com> wrote: >>>> Hi, >>>> >>>> On 2010-06-01 8:33 AM, Armin Ronacher wrote: >>>>> Here a very with line-art for the logo. Feel free to copy the existing >>>>> picture over if you don't like it. >>>> Grammar fail. Should have been "very simple version" I suppose. >>>> >>>> Anyways. Here an alternative proposal with a message in a bottle as >>>> proposed on #pocoo or somewhere in that mailinglist. >>>> >>>> http://dev.pocoo.org/~mitsuhiko/flask-mail.png >>>> >>>> >>>> Regards, >>>> Armin >>>> >>> >> >
Thanks Dan I perform this outside the web environment with a cron, however it loads the database environment. I use smptlib because I do need to send a slightly different message to each person (inserting their name into the email). So far I havn't had a need to load flask but I don't see any reason why not to use flask-mail for this process then. Looking forward to testing the bulk-send. -- Thadeus On Thu, Jun 10, 2010 at 12:26 AM, Dan Jacob <danjac354@gmail.com> wrote: > I've added bulk send functionality to the flask-mail repository, once > fully tested it will be in next release. > > On 10 June 2010 07:16, Dan Jacob <danjac354@gmail.com> wrote: >> Having looked at the source code, it appears that the Relay instance >> actually creates the connection before each send(). >> >> However in the case of sending 5000 mails, you just pass in your 5000 >> mail addresses to the Message.recipients, and they will be sent under >> the same connection. >> >> If however you require sending a slightly different Message instance >> to 5000 recipients, perhaps we can look at adding some bulk send >> functionality that reuses the same connection. >> >> On 9 June 2010 23:54, Dan Jacob <danjac354@gmail.com> wrote: >>> The connection is created and wrapped in a Lamson Relay instance which >>> is monkeypatched to the application as mail_relay. >>> >>> You can also use a different relay instance if you want to. >>> >>> The same connection is therefore re-used across all messages when you >>> call send(). >>> >>> That said, I'd be interested in seeing how efficient it is to use >>> flask-mail for high volume message batches, although that sounds like >>> something that should be done outside the web process in any case. >>> >>> On 9 June 2010 14:51, Thadeus Burgess <thadeusb@thadeusb.com> wrote: >>>> Question: >>>> >>>> If I need to send a batch of emails, does flask-mail open a new SMTP >>>> connection for each msg.send() or is there a way to open a connection, >>>> send my batch of emails (roughly 5000) and then close the connection? >>>> Currently I am just using smtplib to perform this operation. >>>> >>>> -- >>>> Thadeus >>>> >>>> >>>> >>>> >>>> >>>> On Tue, Jun 1, 2010 at 5:20 PM, Armin Ronacher >>>> <armin.ronacher@active-4.com> wrote: >>>>> Hi, >>>>> >>>>> On 2010-06-01 8:33 AM, Armin Ronacher wrote: >>>>>> Here a very with line-art for the logo. Feel free to copy the existing >>>>>> picture over if you don't like it. >>>>> Grammar fail. Should have been "very simple version" I suppose. >>>>> >>>>> Anyways. Here an alternative proposal with a message in a bottle as >>>>> proposed on #pocoo or somewhere in that mailinglist. >>>>> >>>>> http://dev.pocoo.org/~mitsuhiko/flask-mail.png >>>>> >>>>> >>>>> Regards, >>>>> Armin >>>>> >>>> >>> >> >
Can you use this with regular SMTP servers or do you have to use a lamson server? -- Thadeus On Wed, Jun 9, 2010 at 6:51 AM, Thadeus Burgess <thadeusb@thadeusb.com> wrote: > Question: > > If I need to send a batch of emails, does flask-mail open a new SMTP > connection for each msg.send() or is there a way to open a connection, > send my batch of emails (roughly 5000) and then close the connection? > Currently I am just using smtplib to perform this operation. > > -- > Thadeus > > > > > > On Tue, Jun 1, 2010 at 5:20 PM, Armin Ronacher > <armin.ronacher@active-4.com> wrote: >> Hi, >> >> On 2010-06-01 8:33 AM, Armin Ronacher wrote: >>> Here a very with line-art for the logo. Feel free to copy the existing >>> picture over if you don't like it. >> Grammar fail. Should have been "very simple version" I suppose. >> >> Anyways. Here an alternative proposal with a message in a bottle as >> proposed on #pocoo or somewhere in that mailinglist. >> >> http://dev.pocoo.org/~mitsuhiko/flask-mail.png >> >> >> Regards, >> Armin >> >
You can use any SMTP server - the Lamson code used by flask-mail just wraps low-level smtplib functionality. On 9 June 2010 14:54, Thadeus Burgess <thadeusb@thadeusb.com> wrote: > Can you use this with regular SMTP servers or do you have to use a > lamson server? > > -- > Thadeus > > > > > > On Wed, Jun 9, 2010 at 6:51 AM, Thadeus Burgess <thadeusb@thadeusb.com> wrote: >> Question: >> >> If I need to send a batch of emails, does flask-mail open a new SMTP >> connection for each msg.send() or is there a way to open a connection, >> send my batch of emails (roughly 5000) and then close the connection? >> Currently I am just using smtplib to perform this operation. >> >> -- >> Thadeus >> >> >> >> >> >> On Tue, Jun 1, 2010 at 5:20 PM, Armin Ronacher >> <armin.ronacher@active-4.com> wrote: >>> Hi, >>> >>> On 2010-06-01 8:33 AM, Armin Ronacher wrote: >>>> Here a very with line-art for the logo. Feel free to copy the existing >>>> picture over if you don't like it. >>> Grammar fail. Should have been "very simple version" I suppose. >>> >>> Anyways. Here an alternative proposal with a message in a bottle as >>> proposed on #pocoo or somewhere in that mailinglist. >>> >>> http://dev.pocoo.org/~mitsuhiko/flask-mail.png >>> >>> >>> Regards, >>> Armin >>> >> >
On 06/01/2010 08:33 AM, Armin Ronacher wrote: > On 2010-06-01 7:56 AM, Dan Jacob wrote: >> I was going to ask you what font you used, thanks :-) > Here a very with line-art for the logo. Feel free to copy the existing > picture over if you don't like it. > > http://dev.pocoo.org/~mitsuhiko/flask-mail.png > > > Regards, > Armin I like this logo, very cool ;)
Thanks, will do. On 1 June 2010 07:33, Armin Ronacher <armin.ronacher@active-4.com> wrote: > On 2010-06-01 7:56 AM, Dan Jacob wrote: >> I was going to ask you what font you used, thanks :-) > Here a very with line-art for the logo. Feel free to copy the existing > picture over if you don't like it. > > http://dev.pocoo.org/~mitsuhiko/flask-mail.png > > > Regards, > Armin >