*
EMAIL | IMAP + SMTP
 *

*Compose Email | Save as Draft + Send via SMTP*

*
*
* *

Please look at the code below and give me some feedback on how to improve 
it.


*ComposeMail()*

— Creates a form with Email fields

— If form accepted » Save as Draft in IMAP | Send via SMTP

*ConfirmSent()*

— Just a debugger to see if the email has been saved or sent.

— Supposed to show the latest email in the Drafts or Sent folder



*CONTROLLER*


*def ComposeMail():
    *form = SQLFORM 
<http://127.0.0.1:8000/examples/global/vars/SQLFORM>.factory(
        Field <http://127.0.0.1:8000/examples/global/vars/Field>("subject", 
requires=IS_NOT_EMPTY 
<http://127.0.0.1:8000/examples/global/vars/IS_NOT_EMPTY>()),
        Field <http://127.0.0.1:8000/examples/global/vars/Field>("body", 
"text", requires=IS_NOT_EMPTY 
<http://127.0.0.1:8000/examples/global/vars/IS_NOT_EMPTY>()),
        Field <http://127.0.0.1:8000/examples/global/vars/Field>("to", 
requires=IS_NOT_EMPTY 
<http://127.0.0.1:8000/examples/global/vars/IS_NOT_EMPTY>()),
        Field <http://127.0.0.1:8000/examples/global/vars/Field>("attachment", 
"upload") )

    if form.accepts(request 
<http://127.0.0.1:8000/examples/global/vars/request>.vars):

*        *draft_id = imapdb.Gmail_Drafts.insert(to=form.vars.to, 
subject=form.vars.subject, content=form.vars.body, draft=True)

        mail.send(
            form.vars.to,
            form.vars.subject,
            form.vars.body,
            # attachments = mail.attachment(form.vars.attachment),
            )

*        *redirect <http://127.0.0.1:8000/examples/global/vars/redirect>(URL 
<http://127.0.0.1:8000/examples/global/vars/URL>(f="ConfirmSent"))

    return dict(form=form)


*def ConfirmSent():*
    import 
datetime
    messageSent = imapdb(imapdb.Gmail_Sent_Mail.created == 
datetime.date.today()).select().first()
    messageSaved = imapdb(imapdb.Gmail_Drafts.created == 
datetime.date.today()).select().first()
    return dict(Sent=messageSent, Saved=messageSaved)




*VIEWS*


*ComposeMail()*


{{=BEAUTIFY <http://127.0.0.1:8000/examples/global/vars/BEAUTIFY>(response 
<http://127.0.0.1:8000/examples/global/vars/response>._vars)}}



*ConfirmSent()*

*
*

{{=BEAUTIFY <http://127.0.0.1:8000/examples/global/vars/BEAUTIFY>(response 
<http://127.0.0.1:8000/examples/global/vars/response>._vars)}}








*Questions*

*— How to extract files (attachments) from an HTML form and append it to an 
email message in MIME Multipart format?*

*— How to modify the code above for the same? *



 

*— PRACHI*






 

 



 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to