Dear Alan and Massimo,

First, please look at this site:

*http://www.html5rocks.com/en/tutorials/file/dndfiles/*


It shows how to upload and read multiple files directly using HTML5 *(and 
JavaScript)*.
It uses the *File API specification* from W3:

http://www.w3.org/TR/file-upload/



How to implement that in Web2Py for Email Composing with File Attachments?


*Controller*


def Composer():
    form = FORM <http://localhost:8000/examples/global/vars/FORM>(TABLE 
<http://localhost:8000/examples/global/vars/TABLE>(
        TR <http://localhost:8000/examples/global/vars/TR>('Subject:', INPUT 
<http://localhost:8000/examples/global/vars/INPUT>(_type='text', 
_name='subject',
           requires=IS_NOT_EMPTY 
<http://localhost:8000/examples/global/vars/IS_NOT_EMPTY>())),
        TR <http://localhost:8000/examples/global/vars/TR>('Email To:', INPUT 
<http://localhost:8000/examples/global/vars/INPUT>(_type='text', 
_name='emailto', _multiple="",
           requires=IS_EMAIL 
<http://localhost:8000/examples/global/vars/IS_EMAIL>())),
        TR <http://localhost:8000/examples/global/vars/TR>('Save Draft?', 
SELECT <http://localhost:8000/examples/global/vars/SELECT>('yes', 'no', 
_name='savedraft',
           requires=IS_IN_SET 
<http://localhost:8000/examples/global/vars/IS_IN_SET>(['yes', 'no']))),
        TR <http://localhost:8000/examples/global/vars/TR>('Body', TEXTAREA 
<http://localhost:8000/examples/global/vars/TEXTAREA>(_name='body',
           value='Body of email')),
        *TR <http://localhost:8000/examples/global/vars/TR>( 'File', INPUT 
<http://localhost:8000/examples/global/vars/INPUT>(_type='file', _id="files", 
_name="files[]", _multiple="", _value='File test')*
* ),        *TR <http://localhost:8000/examples/global/vars/TR>('', INPUT 
<http://localhost:8000/examples/global/vars/INPUT>(_type='submit', 
_value='EMAIL'))
    ))
    
    if form.process().accepted:
        response <http://localhost:8000/examples/global/vars/response>.flash = 
'Form accepted'
        
        if form.vars.savedraft:
            *## SAVE DRAFT on IMAP ##*
            draft_id = imapdb.Gmail_Drafts.insert(
                        to=form.vars.emailto, subject=form.vars.subject, 
content=form.vars.body, draft=True,
                        *attachments = [ mail.Attachment( 
form.vars.FILE.file.read(), filename=form.vars.FILE.filename ) ]*
                        )
            response.flash = 'Email Saved'
        else:
            *## SEND Email by SMTP ##*
            mail.send(
                  to = form.vars.emailto,
                  subject = form.vars.subject,
                  message = (form.vars.body, '<html>' + form.vars.body + 
'</html>'),
                  *attachments = [ mail.Attachment( form.vars.FILE.file.read(), 
filename=form.vars.FILE.filename ) ]*
                  )
            response.flash = 'Email Sent'

    elif form.errors:
        response <http://localhost:8000/examples/global/vars/response>.flash = 
'Errors in form'
    else:
        response <http://localhost:8000/examples/global/vars/response>.flash = 
'Compose Email'

return dict(form=form) 





*Questions*

   - How to use   *<input type='file', name="files[]", multiple="">*   to 
   input files for Attachment to email?
   - How to extract the required file attributes and append them directly 
   into the mail message and attachment?
   - If the HTML5 provides a means to input, read and upload files, why 
   cannot we use that directly in web2py Email to read and attach multiple 
   files?
   
 

Please look into this and help implementing this.


Thank you, very much.

Gratefully, 

*PRACHI V*






_


-- 
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/d/optout.

Reply via email to