Tuesday, January 27, 2015

Re: sending email

Can someone please guide me here. i am kinda lost, the other part is ok just the email part i am really lost, please help

here is my view.py the email part is not working

def coporateservices_authorized_Leave(request, id):
    if request.method == 'POST':
        a=newleave.objects.get(id=id)
        form = coporateservices_authoriseleave(request.POST, instance=a)
        if form.is_valid():
           form.save()
           to_emails = [u.email for u in User.objects.filter(id__in=[a.'id'])]
           send_mail("RBV Leave Application Email Testing", "Your Leave have been approved",
          "RBV eLeave <Rbv_eLeave_System>", [to_emails])
        return render_to_response('thankyou.html')
    else:
        a=newleave.objects.get(id=id)
        form =  coporateservices_authoriseleave(instance=a)
    return render_to_response('coporate_services_leave_approvial.html', {'form': form}, context_instance=RequestContext(request))

cheers,





On Wed, Jan 28, 2015 at 7:18 AM, Collin Anderson <cmawebsite@gmail.com> wrote:
Hi,

You should be able to figure out which box is checked from form.cleaned_data.

Collin

On Sunday, January 25, 2015 at 11:53:12 PM UTC-5, suabiut wrote:
Hi Collin,
Thank you very much for your help. its works perfectly.
The next thing i want to do is to send an email to a specific user that i select on a table. when an authorized user select a user to approve his or her leave i want an email to be send to the user. so basically when i click on the checkbox on the Test User form the table below. i should get a form to approve the leave as below. now when i click on authorized Leave button an email should be send to the test user. please point me to right direction.
 Inline image 1

Inline image 2

Cheers,

On Fri, Jan 23, 2015 at 1:18 PM, Collin Anderson <cmawe...@gmail.com> wrote:
Hi,

Just query the users you want.

to_emails = [u.email for u in User.objects.filter(username__in=['person1', 'person2', 'person3'])]
send_mail('Subject here', 'Here is the message.', from_email_address, to_emails)

Collin

On Wednesday, January 21, 2015 at 11:29:51 PM UTC-5, suabiut wrote:
Thanks,
I am trying to send email to the users that their email address is stored in the database on the auth_user table. can someone please point me to the right direction.

Cheers,


On Thu, Jan 22, 2015 at 3:03 PM, Collin Anderson <cmawe...@gmail.com> wrote:
Hi,

Yes, this is possible. Something like:

from django.core.mail import send_mail

def authorized_leave(request):
    form
= MyForm()
   
if request.method == 'POST':
        form
= MyForm(request.POST)
       
if form.is_valid():
            obj
= form.save()

            send_mail
('Subject here', 'Here is the message.', 'fr...@example.com', ['t...@example.com'])
           
return redirect('/done/')
   
return render(request, 'template.html', {form: 'form'})

Collin


On Monday, January 19, 2015 at 10:02:45 PM UTC-5, suabiut wrote:
Hi,
I am trying to send an email to several users once a form is submit. I have done the view.py to update the database once the form is submitted and is working fine. what i want to accomplish when the form is submitted is to update the database and at the same time send out email when a user click on the Authorized leave button.

here is the step i want to do:

 Inline image 1

1) user click on the check box and this form below appears


Inline image 2
 2) the user then fill up the form and click on authorized leave button. the form will stored the information into the database. which i have already done it. what i wanted to do next is to also send a emails when the authorized leave button is click. is it possible to send emails and also save data to database when the authorized leave button is click. i want to send email to the Test User which have his email address store in the database.

template.html
<form action ="" method="post">{%csrf_token%}
<table>
{{form.as_table}}
</table>
<br>
<input type="submit" name="submit" value="Authorized Leave" > 


</form>

please point me to the right direction.

Cheers,  

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3df19a0c-2afc-4e17-b527-83d38a639611%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/619e2173-3ac1-4e98-9b91-5c49966ab968%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



-

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7d370efe-301c-4807-a3f3-adf9e980d100%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y78%2BJiYLd53Pn9b3x%2B9vVhmVR-RLRCp1eRdLc_c6ofaKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment