0

I want to test sending out emails. My app used to worked perfectly well in sending notification emails, but for some reason Ubuntu stopped sending emails.

in the settings I have:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'Domain <noreplay@example.com>'

But now it just result in this in postfix mail.log:

Sep 25 15:51:12 mypc postfix/qmgr[15230]: 45353742FF3: from=<ma@mine.com>, size=368, nrcpt=1 (queue active)
Sep 25 15:51:16 mypc postfix/smtp[16989]: connect to alt4.gmail-smtp-in.l.google.com[1.2.3.4]:25: Connection timed out
Sep 25 15:51:16 mypc postfix/smtp[16989]: 4224474301B: to=<somerecepient123@gmail.com>, relay=none, delay=150, delays=0/0/150/0, dsn=4.4.1, status=deferred (connect
to alt4.gmail-smtp-in.l.google.com[1.2.3.4]:25: Connection timed out)
Sep 25 15:51:31 mypc postfix/smtp[17491]: connect to gmail-smtp-in.l.google.com[4.5.6.7]:25: Connection timed out
Sep 25 15:51:42 mypc postfix/smtp[17512]: connect to gmail-smtp-in.l.google.com[4.5.6.7]:25: Connection timed out

This is while postfix seems to work:

$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mypc.localdomain ESMTP Postfix (Ubuntu)

And can even telnet to gmail:

$ telnet smtp.gmail.com 587
Trying 2a00:1450:400c:c09::6d...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP h7sm3532809wjz.7 - gsmtp

I have reinstalled postfix and copied original main.cf. no chance! I also tried to send emails using a gmail account:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'someuser@gmail.com'
EMAIL_HOST_PASSWORD = 'somesupersecret'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = 'domain <noreplay@example.com>'

But I get similar timeout error in the mail.log

It is really frustrating because the app used to send emails to gmail before. After hours of struggling I'm left clueless. So really appreciate your hints.

Jand
  • 2,527
  • 12
  • 36
  • 66
  • 1
    related: http://serverfault.com/questions/585503/postfix-connection-timed-out-on-all-outbound-email – Hedde van der Heide Sep 25 '15 at 14:25
  • @HeddevanderHeide both port 25 and 80 traceroutes are in vein (that is end with `30 * * *`) . What can be wrong here? – Jand Sep 25 '15 at 14:31
  • On your postfix log, you can see that it's trying to connect to gmail on port 25. In my country, all ISP are block outgoing connections to port 25 by default (to prevent spam). I'd try to connect to gmail on telnet using port 25 to see if it works (you connected on port 587). – Tiago Sep 25 '15 at 14:33
  • @Tiago using port 25 for google gives the same timeout error. However port 25 is open to 127.0.01 so it should not be an issue in the first scenario when I try to send email through local smtp. right? – Jand Sep 25 '15 at 14:46
  • @Paulrx: It's an issue because while you can connect to your localhost:25 postfix server, your local postfix server can't connect from your machine to the remote SMTP server, in this case Google's server, to deliver the email. – Tiago Sep 25 '15 at 14:56
  • @Tiago. You are right. So is there any way to bypass this port blocking? – Jand Sep 25 '15 at 14:57
  • 1
    @Paulrx: I believe the only way is to use an external SMTP service. You can use SendGrid/MailGun (both offer free accounts for small volumes) for instance, set them up on django, and your local machine will connect there and they'll relay the email for you. – Tiago Sep 25 '15 at 15:19
  • If you need to send email through port 25 some ISPs will unblock this port for you on request. – MrAlexBailey Sep 25 '15 at 15:34
  • @Tiago using MailGun instead of gmail solved my problem. So feel free to elaborate your answer and I'll accept it. Many thanks! – Jand Sep 25 '15 at 16:12

0 Answers0