1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How can I send email via Django?

Discussão em 'Python' iniciado por Stack, Novembro 25, 2025.

  1. Stack

    Stack Membro Participativo

    In my settings.py file, I have the following:

    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

    # Host for sending e-mail.
    EMAIL_HOST = 'localhost'

    # Port for sending e-mail.
    EMAIL_PORT = 1025

    # Optional SMTP authentication information for EMAIL_HOST.
    EMAIL_HOST_USER = ''
    EMAIL_HOST_PASSWORD = ''
    EMAIL_USE_TLS = False


    My email code:

    from django.core.mail import EmailMessage
    email = EmailMessage('Hello', 'World', to=['user@gmail.com'])
    email.send()


    Of course, if I set up a debugging server via python -m smtpd -n -c DebuggingServer localhost:1025, I can see the email in my terminal.

    However, how do I actually send the email not to the debugging server, but to user@gmail.com?

    After reading your answers, let me get something straight:


    1. Can't you use localhost (simple Ubuntu PC) to send e-mails?


    2. I thought in Django 1.3 send_mail() was somewhat deprecated and EmailMessage.send() was used instead?

    Continue reading...

Compartilhe esta Página