0

Good day, I have a Django app that sends emails. I used a google app password for my EMAIL_HOST_PASSWORD, it works perfectly fine, but the from_email always set to my email which I used to create the app password instead of the email it gets from the form. How can I fix this, please?

UPDATE

from django.shortcuts import render
from django.core.mail import send_mail


def index(request):
    if request.method == "POST":
        name = request.POST["name"]
        email = request.POST["email"]
        phone = request.POST["phone"]
        message = request.POST["message"]

        msg = "Email: " + email + "\n" + message + "\nPhone Number: " + phone

        send_mail(
            name + " Sent Us A Message",
            msg,
            email,
            ["myemail@gmail.com"],
        )

        return render(request, "index.html", {"name": name})
    else:
        return render(request, "index.html", {})
  • Can you show code used to send email? – Jarad Jun 18 '21 at 00:18
  • @Jarad I've updated the question – Adeyemo Toluwanimi Jun 18 '21 at 03:12
  • Since you are using gmail as your smtp server, you specify this under EMAIL_HOST in settings, google won't allow you to use a custom from_email for security reasons. The accepted answer to [this question](https://stackoverflow.com/questions/8418905/how-to-override-the-from-address-in-django-email-sent-through-gmail) explains it better. You can achieve what you are looking for using something like sendgrid or zoho. They also have good documentation on how to send email with django. cheers. – mr blu Jun 18 '21 at 08:52
  • i tried using sendgrid but it keeps returning this error `You will not be able to send email through SendGrid until you provide more information. Please contact Support to answer a few more questions.` and `You are not authorized to access SendGrid, please contact Support.` – Adeyemo Toluwanimi Jul 01 '21 at 22:56

0 Answers0