Sunday, June 30, 2019

Re: Sending Email from form

Basically, you would need to build it in string form.

This could be done through a combination of string interpolation and concatenation.

Here is my quick hack below (I have not shown all the code).

There is a cleaner way to do this, e.g. using templates, but I wanted something that would "just work" for the time being.

first_name = form.cleaned_data['first_name']
last_name = form.cleaned_data['last_name']
start_date = form.cleaned_data['start_date']
number = form.cleaned_data['number']
message = form.cleaned_data['message']
number_of_people = form.cleaned_data['number_of_people']
if is_type == 'admin':
sender = form.cleaned_data['email']
return 'Booking request for "{}" tour starting '.format(tour) + str(start_date) + ' from {} {}.'.format(first_name, last_name) + \
'\n\nNumber of people: {}'.format(number_of_people) + \
'\n\nThe message is as follows: \n\n"' + message + \
'"\n\nSent by: {} {}'.format(first_name, last_name) + '\n' + sender + '\n' + number
elif is_type == 'client':
return 'Dear ' + first_name + ' ' + last_name + ',\n\n' +\
'Your booking request for our "{}" Tour has been received.'.format(tour) + \
'\n\nNumber of people: {}'.format(number_of_people) + \
'\n\nThe message is as follows: \n\n"' + message + \
'"\n\nWe will respond as soon as possible.' +\

Kind regards,
Lloyd


Sent with Shift

On Sat, Jun 29, 2019 at 8:00 PM Emmanuel klutse <nuelklus@gmail.com> wrote:
Thanks ones again, 
-How do I build a message and include the email in its text please. I can I get a snippet please. 
Thanks 

On Sat, 29 Jun 2019 at 5:28 PM, Sithembewena L. Dube <zebra05@gmail.com> wrote:
You're welcome Emmanuel.

Fyi, I think using one email as the 'from' address and sending the user-provided one in the email body may be easier, as mail sent from different addresses yet from the same mail server IP address may be flagged as spam (Barracuda Networks is an example of such an enforcer).

My solution was as follows:

- Declare a Django Form that accepts the email address. Call the field whatever you like, e.g. 'email_address'
- In your view, if request.method == 'POST':
-    if form.is_valid():
-        email_address = form.cleaned_data['email_address']
- Build a message and include the email in its text
- Call send_mail(...) and use an email address you provided (as the 'from' address)


Kind regards,
Lloyd


Sent with Shift

On Sat, Jun 29, 2019 at 6:25 AM Emmanuel klutse <nuelklus@gmail.com> wrote:
Thank you Dube!!! Will check it out and update shortly. 

Sent from my iPhone

On 29 Jun 2019, at 2:27 AM, Sithembewena L. Dube <zebra05@gmail.com> wrote:

I just finished a project where I did the same thing you require.

I used the Mailgun API.

The relevant documentation can be found here:
https://documentation.mailgun.com/en/latest/user_manual.html#sending-via-api

Kind regards,
Lloyd


Sent with Shift

On Fri, Jun 28, 2019 at 8:22 PM Emmanuel klutse <nuelklus@gmail.com> wrote:
Hello Team. 
I'm new to programming and I've been studying Django for 6 months now. I just started my first project and i need help with handling sending emails from a user form.
I am using send_mail function to allow anyone who wants to contact me through my contact page. Its is working fine but I need a way for Django to allow me get an email from my application using the email address provided by the user in fill the form instead of the one I provided in settings.py.
Please help…. I have been on this for the past one week. 

I'm also available to assisting anyone who needs someone with my level on a project for free. 

Thank you
Emmanuel klutse
+233202729851

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/60A5D9BF-5096-4824-90D2-7149E1ACC82E%40gmail.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAH-SnCDv4dz8%2BFyr3%2By-0GUxX41Nbnv%2BjsXrgnquOGVHp83vpw%40mail.gmail.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 https://groups.google.com/group/django-users.

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAH-SnCAQnTp20Koy8z2XkN11OdUHTLMx50nr%3DpFbimsLRhYWCg%40mail.gmail.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAw18mD_n30dUEVhaeGRDzg%2B1-Xsquv8Pq1mdKK8tCPAXgvP1w%40mail.gmail.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAH-SnCC1-kXpfJckXSjKqouX-chRYpPLDooR4LREfv1pkjW42g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment