connect to smtp.gmail: Connection refused

5,757

I have emulated firewall issue

# host smtp.gmail.com
smtp.gmail.com is an alias for gmail-smtp-msa.l.google.com.
gmail-smtp-msa.l.google.com has address 74.125.136.109
gmail-smtp-msa.l.google.com has address 74.125.136.108
gmail-smtp-msa.l.google.com has IPv6 address 2a00:1450:4013:c01::6d

# iptables -I OUTPUT -d 74.125.136.108 -j DROP
# iptables -I OUTPUT -d 74.125.136.109 -j DROP

Check connection

# openssl s_client -connect smtp.gmail.com:587 -starttls smtp
socket: Network is unreachable
connect:errno=101

these lines mean that someone on you network is blocking connection to smtp.gmail.com on port 587. You can try another smtp server: smtp-mail.outlook.com:25, smtp.mail.yahoo.com:587, smtp.mail.ru:2525

# openssl s_client -connect smtp.mail.yahoo.com:587 -starttls smtp
CONNECTED(00000003)
depth=3 C = US, O = "VeriSign, Inc.", OU = Class 3 Public Primary Certification Authority
verify return:1
depth=2 C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = "(c) 2006 VeriSign, Inc. - For authorized use only", CN = VeriSign Class 3 Public Primary Certification Authority - G5
verify return:1
depth=1 C = US, O = Symantec Corporation, OU = Symantec Trust Network, CN = Symantec Class 3 Secure Server CA - G4
verify return:1
depth=0 C = US, ST = California, L = Sunnyvale, O = Yahoo Inc., OU = Information Technology, CN = smtp.mail.yahoo.com
verify return:1
...
---
250 STARTTLS
quit
221 2.0.0 Bye
closed

P.S. by the way, have you tried port 465?

# openssl s_client -connect smtp.gmail.com:465
Share:
5,757

Related videos on Youtube

bhawna
Author by

bhawna

Updated on September 18, 2022

Comments

  • bhawna
    bhawna almost 2 years

    I am trying to send mail via Ubuntu 14.04 version to my gmail ID. Ubuntu is running via VMware on my Windows machine. Please let me know if the above description is not clear as I am newbie in working with virtual machine. I haved first installed VMware Workstation 12 Player. Then downloaded ubuntu-14.04.4-desktop-amd64.iso and created a virtual machine for it.

    I am trying to run the below command: echo "This is the body of the email" | mail -s "This is the subject line" myemailID

    There is no error prompt. I have already executed the following utilities on Ubuntu:

    sudo apt-get install mailutils
    sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
    sudo dpkg-reconfigure postfix
    

    I have selected 'Internet site' as mail configuration and rest settings as default. I have checked mail.log file by executing 'tail -f /var/log/mail.log' and following is the message:

    Mar 22 16:34:00 ubuntu postfix/qmgr[2743]: 257891057F0: from=<>, size=474, nrcpt=1 (queue active)
    Mar 22 16:34:00 ubuntu postfix/smtp[2755]: connect to smtp.gmail.com[74.125.70.109]:587: Connection refused
    Mar 22 16:34:00 ubuntu postfix/smtp[2755]: connect to smtp.gmail.com[74.125.70.108]:587: Connection refused
    Mar 22 16:34:00 ubuntu postfix/smtp[2755]: 257891057F0: to=<myemailid>, relay=none, delay=0.07, delays=0/0/0.06/0, dsn=4.4.1, status=deferred (connect to smtp.gmail.com[74.125.70.108]:587: Connection refused)
    Mar 22 16:34:00 ubuntu postfix/pickup[2744]: 3DE6F10580A: uid=1000 from=<>
    Mar 22 16:34:00 ubuntu postfix/cleanup[2753]: 3DE6F10580A: message-id=<20160322110400.3DE6F10580A@ubuntu>
    Mar 22 16:34:00 ubuntu postfix/qmgr[2743]: 3DE6F10580A: from=<>, size=476, nrcpt=1 (queue active)
    Mar 22 16:34:00 ubuntu postfix/smtp[2755]: connect to smtp.gmail.com[74.125.70.108]:587: Connection refused
    Mar 22 16:34:00 ubuntu postfix/smtp[2755]: connect to smtp.gmail.com[74.125.70.109]:587: Connection refused
    Mar 22 16:34:00 ubuntu postfix/smtp[2755]: 3DE6F10580A: to=<myemailid>, relay=none, delay=0.05, delays=0/0/0.05/0, dsn=4.4.1, status=deferred (connect to smtp.gmail.com[74.125.70.109]:587: Connection refused)
    

    Please guide and let me know if any other information is required.

    /etc/postfix/main.cf file is also mentioned below for reference.

    smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
    biff = no
    
    append_dot_mydomain = no
    
    readme_directory = no
    
    
    smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
    smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
    smtpd_use_tls=yes
    smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
    smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
    
    smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
    myhostname = ubuntu
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    mydestination = ubuntu, localhost.localdomain, localhost
    relayhost = [smtp.gmail.com]:587
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    smtp_tls_CAfile = /etc/postfix/cacert.pem
    smtp_use_tls = yes
    smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
    mailbox_size_limit = 0
    recipient_delimiter = +
    inet_interfaces = all
    inet_protocols = ipv4
    mynetworks = 127.0.0.0/8
    mailbox_command = procmail -a "$EXTENSION"
    
    • ALex_hha
      ALex_hha over 8 years
      Looks like firewall issue. You can check 'openssl s_client -connect smtp.gmail.com:587 -starttls smtp'
    • bhawna
      bhawna over 8 years
      here is the output: connect: Connection refused connect:errno=111
    • ALex_hha
      ALex_hha over 8 years
      Could you add the full output to the question?
    • bhawna
      bhawna over 8 years
      this is the complete output, in 2 different lines
    • bhawna
      bhawna over 8 years
      connect: Connection refused
    • bhawna
      bhawna over 8 years
      connect:errno=111
  • bhawna
    bhawna about 8 years
    Thanks for the help... I deleted Ubuntu virtual machine and re-created it. It is now able to send mails to gmail. Thanks a lot:) What I am trying now is to send email to my yahoo and office ID, which is not working. Any pointers are appreciated. This is the log I receive for smtp yahoo server.
  • bhawna
    bhawna about 8 years
    openssl s_client -connect smtp.mail.yahoo.com:587 -starttls smtp....................... CONNECTED(00000003) depth=2 C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = "(c) 2006 VeriSign, Inc. - For authorized use only", CN = VeriSign Class 3 Public Primary Certification Authority - G5 verify error:num=20:unable to get local issuer certificate verify return:0 --- Certificate chain 0 s:/C=US/ST=California/L=Sunnyvale/O=Yahoo Inc./OU=Information Technology/CN=smtp.mail.yahoo.com i:/C=US/O=Symantec Corporation/OU=Symantec Trust Network/CN=Symantec Class 3 Secure Server CA - G4