Send and save as draft email forms

91 views
Skip to first unread message

Alan Etkin

unread,
Aug 17, 2013, 8:18:19 AM8/17/13
to web...@googlegroups.com
This is a question from a web2py user that was sent to my mail. Has anybody solved this?
 
Q: How do we create a Compose Form in web2py to compose, save and send an Email?
Do you have any examples or references that we can look at?

 
Also how to do the Send versus Save as Draft form creation – because Save will have to access the IMAP server, whereas the Send will have to use the SMTP server?

We have been trying to do this for a long time, and the FORM or SQLFORM or CRUD form are not helping us to build a compose window. Any help, guidance or reference would be very helpful.
Thank you, once again.

With Gratitude,
Prachi

Alan Etkin

unread,
Aug 17, 2013, 8:46:36 AM8/17/13
to

Q: How do we create a Compose Form in web2py to compose, save and send an Email?

I'd use SQLFORM.factory to collect the mail data and, after the form submission, use the welcome app's mail object to send the message with smtp (passing the user's smtp connection parameters maybe stored in the app's database).
 
Do you have any examples or references that we can look at?

No, but the book's forms, DAL and email chapters should be enough reference to implement the feature.
 
Also how to do the Send versus Save as Draft form creation – because Save will have to access the IMAP server, whereas the Send will have to use the SMTP server?

There's no draft support in the imap adapter (but I will open an enhancement issue about it). However, you could implement your own draft service storing email drafts in the application's database.

EDIT: Note that currently it should be possible to mark a message as draft with <message Row>.update_record(draft=True), but the adapter does not support appending messages to the mailbox.

Alan Etkin

unread,
Aug 17, 2013, 8:54:37 AM8/17/13
to web...@googlegroups.com
I have opened an issue requesting the mail storage feature.

https://groups.google.com/d/msg/web2py/WrFGJhGI8ds/q8SvGEuZwZUJ

PRACHI VAKHARIA

unread,
Aug 17, 2013, 11:04:23 AM8/17/13
to web...@googlegroups.com

Below are the main features that are required for Email »
  1. Reading (IMAP-POP)
  2. Writing (composing)
  3. Saving (drafts)
  4. Sending (SMTP)
  5. Managing Attachments
  6. Fetching Email Headers only
Features 1 and 4 do exist in w2p, and is very well executed.
When the rest of the features are also implemented in the same simple and structured manner, that would make w2p extremely powerful in handling Emails. But it is important to make it simple, structured and seamless so that it is consistent with the rest of w2p.

Thank you.
— Prachi


.

Alan Etkin

unread,
Aug 17, 2013, 12:37:54 PM8/17/13
to web...@googlegroups.com
6. Fetching Email Headers only

AFAIK, that is implemented already. The adapter only fetches the whole message if the fields selected do not belong to the header. For example:

>>> imap(...).select(imap.inbox.sender, imap.inbox.created, imap.inbox.subject)

would only fetch the header.

PRACHI VAKHARIA

unread,
Aug 17, 2013, 1:29:41 PM8/17/13
to web...@googlegroups.com
Thanks for the clarification. It was my assumption and misunderstanding that the adapter fetched the full email with MIME parts, and that it was parsed later to return only header information.

It would be great and neat to have the Compose + Draft + Send features also implemented in a simple format.

Thank you.
— Prachi


.

Alan Etkin

unread,
Aug 17, 2013, 5:46:11 PM8/17/13
to web...@googlegroups.com
It would be great and neat to have the Compose + Draft + Send features also implemented in a simple format.

Here's a simple project I started some time ago for a web2py mail client app that you can use as example.

http://code.google.com/p/gpo2py/

Massimo Di Pierro

unread,
Aug 18, 2013, 4:01:26 AM8/18/13
to web...@googlegroups.com
Why should web2py include mail storage? It looks more like an app to me than a core feature.

PRACHI VAKHARIA

unread,
Aug 18, 2013, 4:32:13 PM8/18/13
to web...@googlegroups.com


On Sunday, August 18, 2013 4:01:26 AM UTC-4, Massimo Di Pierro wrote:
Why should web2py include mail storage? It looks more like an app to me than a core feature.



Dear Massimo,
That is a great question, and let me try to make a case for that.
Currently w2p provides DAL abstraction to read IMAP and send emails using SMTP, but (as per what I understood from Alan Etkin — I may have misunderstood as well) it does not allow saving of Email as drafts.
If we imagine IMAP to be a DB for emails, then w2p DAL has the ability to read the IMAP data (emails) but not write, save or append IMAP data (drafts). That is like the ability to read data from an SQL-DB but not having the ability to write to it. And that is a little bit limiting. Of course, there have to be work-arounds for all that. But when there is read and send, why not have save (write-append) too?
Please think about it. Composing of an email message can go in two main directions:
    1. Send » SMTP — this has been implemented
    2. Save as Draft » IMAP — this option appears to be missing.
Send from Drafts » IMAP to SMTP — this can be done currently, but can the draft itself be created?
 
If I have not understood anything properly, please do enlighten me. And if you think that there is any merit to my case above, please consider it favorably.
Thank you.

Regards,
PRACHI




.

Massimo Di Pierro

unread,
Aug 18, 2013, 10:00:40 PM8/18/13
to web...@googlegroups.com
I am convinced. Thanks Prachi. I believe Alan is on the case.
Reply all
Reply to author
Forward
0 new messages