0

I'm trying to send an email (via a contact form) on my Godaddy shared hosting account (I know!). I've simplified it for the purposes of getting it working. I have SSH access. The script is located in my cgi-bin folder. The from email address is a Godaddy domain one (required apparently). I have it working on my test home server (using gmail's smtp server).

#! /usr/bin/python
import smtplib
import string, sys
import cgitb
cgitb.enable()
sys.stderr = sys.stdout

print 'Content-Type: text/plain'
print
HOST = "relay-hosting.secureserver.net"

FROM = "myemail@mygodaddydomain.co.uk"

TO = "mygmail@gmail.com"

SUBJECT = "Test"

BODY = "Hello"

body = string.join((
        "From: %s" % FROM,
        "To: %s" % TO,
        "Subject: %s" % SUBJECT,
        "",
        BODY), "\r\n")

print body
server = smtplib.SMTP(HOST, 25)
server.sendmail(FROM, [TO], body)

I'm getting the following error:

Traceback (most recent call last):
  File "test2.py", line 28, in <module>
    server = smtplib.SMTP(HOST, 25)
  File "/usr/lib64/python2.6/smtplib.py", line 239, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib64/python2.6/smtplib.py", line 295, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib64/python2.6/smtplib.py", line 273, in _get_socket
    return socket.create_connection((port, host), timeout)
  File "/usr/lib64/python2.6/socket.py", line 567, in create_connection
    raise error, msg
error: [Errno 110] Connection timed out

I've been told the Godaddy smtp server settings are correct and have tried a few combinations reading other similar questions on Stackoverflow.

  • Are you sure that `HOST` is correct? What is the official `HOST` value recommended by Godaddy? (If you use different host, the firewall may block the connection, and then you get a timeout.) – pts Oct 21 '14 at 00:23
  • That's what I've been told (by Godaddy) and through Google searches. – archery1234 Oct 21 '14 at 00:25
  • My script is slightly different and includes MIME (but works on my home server). This one is from [link](http://www.johnloomis.org/python/email_test.py.html) written specifically for Godaddy. – archery1234 Oct 21 '14 at 00:29
  • I've also tried `smtpout.secureserver.net` +/- SSL. – archery1234 Oct 21 '14 at 00:54
  • Your program seems to be correct. Your best bet is asking Godaddy support directly, citing this StackOverflow page. – pts Oct 21 '14 at 11:04
  • I've made progress. Rather than setting up the email addresses in cPanel, they should be setup in MyAccount prior to launching cPanel with the SMTP relay server option enabled. I can now send using an `FROM = "email@mydomain.co.uk"` and `HOST = "smtp.europe.secureserver.net"`. The only problem I'm finding is that I can only send `TO = "anotheremail@mydomain.co.uk"` – archery1234 Oct 21 '14 at 17:55
  • Please ask the other problem in a separate question. – pts Oct 21 '14 at 18:01
  • Is this not the same problem i.e. getting the correct settings to use Godaddy's smtp server in shared hosting accounts? – archery1234 Oct 21 '14 at 18:05

2 Answers2

0

It now works. The solution as far as I can tell was to set up email in the Godaddy Myaccount rather than cpanel and ensure the MX record is correct and make a couple of changes to the smtp module code.

#!/usr/bin/python
import smtplib
import string, sys
import cgitb
cgitb.enable()
sys.stderr = sys.stdout

print 'Content-Type: text/plain'
print

FROM = "email@mygodaddydomain.com"

TO = "myemail@gmail.com"

SUBJECT = "Test"

BODY = "Hello"

body = string.join((
        "From: %s" % FROM,
        "To: %s" % TO,
        "Subject: %s" % SUBJECT,
        "",
        BODY), "\r\n")

print body
server = smtplib.SMTP()
server.connect()
server.sendmail(FROM, TO, body)
-1

You Can User SendGrid APIs with Python Scripts to send emails, just write a scripts that connect with your db and do whatever functions you want to send. then host this python scripts on heroku and make this scripts to schedule run with heroku scheduler adds on.

see this link for running and hosting the scripts

Community
  • 1
  • 1
Muhammad Taqi
  • 5,356
  • 7
  • 36
  • 61