title: Send email using environment variables via Django for security
body: <p>I can send emails using environment variables in my settings.py, however how do I input these variables in views.py? When put the actual email in str--it works; but for extra security, I written it as env. variable and gave me an error: SMTPRecipientsRefused. Also, how do I get it to show the sender's email. It shows in the console, but not when I receive the email. I am trying to get different users to send to one email recipient as contact form.</p>
  
  <p>settings.py:</p>
  
  <pre class="lang-py prettyprint-override"><code>SECRET_KEY = os.environ.get('SECRET_KEY')
  EMAIL_HOST_USER=os.environ.get('EMAIL_HOST_USER')
  EMAIL_HOST_PASSWORD=os.environ.get('EMAIL_HOST_PASSWORD')
  </code></pre>
  
  <p>views.py:</p>
  
  <pre class="lang-py prettyprint-override"><code>def contact(request):
    message = request.POST.get('message', '')
    from_email = request.POST.get('from_email', '')
  
    send_mail('Contact Form', message, from_email, ['EMAIL_HOST_USER'])
    return render(request, 'first_app/contact.html')
  
  </code></pre>
  
  <p>contact.html:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form action="/contact" method="POST"&gt;
    {% csrf_token %}
    &lt;input type="email" name="from_email" placeholder="Your email"&gt;
    &lt;textarea name="message" placeholder="Message..."&gt;
    &lt;/textarea&gt;
    &lt;input type="submit"/&gt;
  &lt;/form&gt;
  </code></pre>