I haven't had a good experience with mail.send
It seems to block python which is a problem if you have a single process 
webserver (like Rocket, or apache on windows) . 
You should probably use the scheduler for sending mail (since this means 
the process which gets blocked is not the webserver). 

gmail has a REST API which I assume is non blocking; I'm going to learn how 
to use that in the next couple of weeks for a client which has migrated to 
Google Apps. This is I hope a good, reusable solution for sending single 
emails without needing a mail processing queue via the scheduler. 




On Friday, 24 October 2014 01:16:46 UTC+11, Massimo Di Pierro wrote:
>
> This should help:
>
> def index():
>     form = FORM(INPUT(_type='file', _id="files", _name="files", 
> _multiple=True, _value='File test'),
>                 INPUT(_type="submit")).process()
>     if form.accepted:
>         for item in form.vars.files:
>             print item.filename, item.file.read()
>     return dict(form=form)
>
> On Wednesday, 22 October 2014 00:01:06 UTC-5, PRACHI VAKHARIA wrote:
>>
>>
>>
>>
>>  
>>
>> Dear Alan and Massimo,
>>
>> First, please look at this site:
>>
>> *http://www.html5rocks.com/en/tutorials/file/dndfiles/ 
>> <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