AlexBrand
AlexBrand

Reputation: 12401

sending email with sendmail - django

I set up the sendmail email backend with this snippet

I open the shell and run (with actual email accounts):

from django.core.mail import send_mail

send_mail('Subject here', 'Here is the message.', '[email protected]',
    ['[email protected]'], fail_silently=False)

After that, the console just prints a:

1

No error messages or anything... but the emails never arrive on the other end...

Is there anything else that I need to configure?

Thanks,


Requested the mail server's error logs from my hosting provider and saw this:

 send_to_gateway router failed to expand "${perl{mailtrapheaders2}}": 
 Undefined subroutine &main::mailtrapheaders2 called.\n`

They are still trying to figure it out :S

Upvotes: 1

Views: 3709

Answers (2)

Ilian Iliev
Ilian Iliev

Reputation: 3236

Probably the problem is in your mail server. sendmail connects to the mail server and tells him "take this mail and send it to adress X". If the mail server is working it takes is and says OK, and then tries to send it to the address - if something breaks during the send its mail server error and it is not send to Django.

Check your mail server log, I believe you will find the answer of "why is the main not delivered" there.

Upvotes: 1

Silviu
Silviu

Reputation: 835

In the snippet code:

def send_messages(self, email_messages):
    """
    Sends one or more EmailMessage objects and returns the number of email
    messages sent.
    """

which returns a variable num_sent which is incremented for every mail that has been actually sent. This is the 1 your are seeing displayed in the console.

Upvotes: 2

Related Questions