Handing over eMails from POST to standard Mail-App

Hi folks,

im still new to Django and battling everyday with different things. My Question today:
Let’s say, i have a template with a list of People including their eMail-Adresses. Let’s say, i have put some checkboxes to the eMail adresses and included a Button to the site which says “send Mail to all checked adresses”.

AND let’s say, that this after all WORKS (i get the checked adresses flawlessly written in console when using “print(request.POST)”…so the template is posting the desired informations. But what next?

I would like to set up a procedure in the view under the

if request.mehod == ‘POST’

where all posted mail adresses are forwarded to the standard mail program of the used OS…and in best case they are insertet not in normal recipient field but to BlindCopy (on behalf of some data security regulations)…

For sending email, see Sending email | Django documentation | Django

However, you wrote:

First, there is no such thing as a “standard mail program”.

Second, you don’t send mail through the user’s email client - you send emails out through an email server, usually through SMTP. How the user retrieves those emails is up to them.

Ok, maybe we are talking about different things. Of course, there is a standard mail programm of an os. It has to be set up within the os configuration, that is true but what i am talking about is: When i am clicking on a marked href:“mailto” link, on my PC, Microsoft Outlook pops-up and offers me the opportunity to send a mail to this contact i have clicked seconds ago…

Hope that helps to clarify

Means: I dont want to sent eMails via DJANGO itself, i just want to know how to make django hand over several email-addresses to the standard mail programm of used os. As it works with “mailto” entries on template.
In best case, for mail to many recipients, data should be passed to the BCC Field of Mail-App :wink:

No, there isn’t.

There might be a default selected when an OS is configured for use, but there is no standard. Microsoft Outlook is not the “standard”, it is one option among many. The best you can say is that it’s the default for that particular user.

However, that still doesn’t mean that the browser is going to open that application when a mailto link is clicked. That is something that may be configured within the browser itself. (For example, see the Applications options in the General section of the settings within Firefox.)

As a result, there is no “guaranteed-to-work” method for opening up the email client from a browser and ensuring that certain fields are filled out.


for more details.

Seriously? We are text-battling about “standard” and “default” besides the fact that you meanwhile surely know what i am talking about ? I am no native english speaker.

Thanks for the references, but references to this topic i got a lot before posting here. Posting references is no (or in rare cases) help for a specific question but only a tool for raising own post-counts…

I am impressed. I give you great credit for your education - that certainly hasn’t been evident from the written quality of your posts. And your English is far superior than my knowledge of whatever your native language may be.

Going back to the earlier posts:

Those links give you the specifics of how you can create a link in a page to open up whatever email client the user has configured in their browser, and (potentially) supply information for that email.

Beyond that, no, I’m not sure what you’re asking for at this point.

First: I’m sorry about my rough reply last time. was tired and annoyed due to some things the kids had done :stuck_out_tongue: So take this please for an apology, because i know that nobody HAS to spend time here answering questions. I appreciate your support. Will read your posted links again carefully and if afterwards something should be still troubling me, i will post here again.

No worries, I understand how frustrating this can be - especially when working in your non-native language. I think if we can get to a common understanding of what you’re trying to accomplish here, we’ll get answers.

so i have read your links and some others and i solved my problem, what i wanted to do was simply something like this :slight_smile:

{% if priv_mails %}
    {% if comp_mails != None %}
        <meta http-equiv="refresh" content="0;url=
        mailto:{% for comp_mail in comp_mails %}{{ comp_mail }}{% if not forloop.last %},%20{% endif %}{% endfor %}
        ?bcc={% for priv_mail in priv_mails %}{{ priv_mail }}{% if not forloop.last %},%20{% endif %}{% endfor %}" />

     {% else %}
        <meta http-equiv="refresh" content="0;url=
        ?bcc={% for priv_mail in priv_mails %}{{ priv_mail }}{% if not forloop.last %},%20{% endif %}{% endfor %}" />

    {% endif %}

{% elif comp_mails %}

     <meta http-equiv="refresh" content="0;url=
     mailto:{% for comp_mail in comp_mails %}{{ comp_mail }}{% if not forloop.last %},%20{% endif %}{% endfor %}" />

{% endif %}

Thanks for the help!

NEXT nebwie question on same topic: Now i have to deal with the char-number-limitation of mailto-hand-overs. Is there a way to count the chars in a POST-Array?

I tried several approaches with “len”, “Length” or “count” but the best result was the correct number of eMail adresses in the given POST, but i would need the sum off all CHARS in POST…

I’m not aware of any way of doing it in the template language. You could either write some JavaScript to calculate it, or calculate it in the view before rendering the data in the template.

preferred solution would be to calculate it in the view. something like request.POST[‘eMail’].totalcharcount :wink:

You’ll need to calculate the sum of the lengths of the individual strings in the list.

so something like

for element in elements:

but since i am still new to python i have no idea how to aggregate the single len-values or to sum it up…

think this could work. thx

            priv_mails = request.POST.getlist('eMail')
            comp_mails = request.POST.getlist('cMail')
            length_priv = 0
            length_comp = 0
            length_total = 0
            for priv_mail in priv_mails:
                length_priv += len(priv_mail)
            for comp_mail in comp_mails:
                length_comp += len(comp_mail)

            length_total = length_priv + length_comp

You could do something like:
length_priv = sum([len(email) for email in request.POST.getlist('eMail')])

I will try, could shorten the code a bit. Thx for Yoru help :slight_smile: