Month: October 2017

Bluehost Domain Account Email Forwarding to Gmail

Bluehost Domain Account Email Forwarding to Gmail

Every website deserves its own email with the domain name in the address. I’m using Bluehost for my wordpress blog which comes with several free email accounts, it’s just up to you to make use of them. You have the option to utilize a free mail client, use an existing one, or forward along any received emails to a personal account. I use Gmail as my primary mail client, and want to enjoy the comfort I have in the application while managing my domain account email, so I’ll be setting up email forwarding. Along with forwarding, I’ll want to have the ability to respond from my Gmail account with my Bluehost domain account email as the sender.

Let’s go over the goals of this post:

  • Setup an email with Bluehost
  • Forward emails from Bluehost to your Gmail, and setup Gmail to respond as your Bluehost domain account email

Create Your Bluehost Domain Account Email

A domain account email is one where the domain name of your website comes after the @. For example, [email protected]. Looks pretty good, right? Fortunately, this is incredibly easy to setup.

  1. Log into your Bluehost control panel, then select the Email tab on the left-hand menu
  2. Once selected, enter a solid password (look at that 100/100) and create your account

Bluehost Domain Account Email

Now we have a new email address created which can begin receiving emails. Perfect, now let’s forward those emails to a client we’re more comfortable with like Gmail.

Forward Domain Emails to Gmail

When an email is sent to your Bluehost domain account email, a copy of that email will be forwarded along to the email you specify in the below steps. Email forwarding in this case will allow us to avoid having to manage our email through a separate client:

  1. Back in the Bluehost cPanel, under the Email tab on the left-hand menu, click Forwarders
  2. In the forwarders screen, click the Add Forwarder button. You can also click the Add Domain Forwarder if you’d like to forward any and all emails sent to any Bluehost domain account email you have configured. For now, we’ll stick to just forwarding the onecPanel Forwarders
  3. Fill in the forwarding email account, then click Add Forwarder

    Add Forwarder

That’s it, now your domain email account will have its mail forwarded along to your personal account. Give it a shot: email your domain account email and see if your personal gets a copy. This didn’t work immediately for me, there may be a delay for these changes to propagate. If at first it doesn’t work, give it a little while and try again.

Email forwarding is configured, nice work! Now let’s setup our personal Gmail to allow replying as our domain account email.

Replying to Forwarded Emails as the Domain Account

Gmail allows you to setup additional “send as” accounts when composing a new email. By defining another “send as” email account, we can reply to emails that are forwarded from our website domain account email as the domain account email. Let’s set that up:

  1. Log into your Gmail account
  2. At the top right, click the settings icon Gmail Settings Gear, then choose Settings
  3. In the settings window, select Account and Import, then Add another email addressGmail Add Another Email Address
  4. In the resulting window, enter your domain account email that you’re forwarding from. Leave the Treat as alias checkbox checked, then click Next
  5. You’ll be prompted for the SMTP server, username and password. The SMTP server should be your website domain name prefixed with “mail”. For example, mail.storiknow.com. Your credentials will be whatever you use to log into Bluehost.
  6. Once authenticated, Google will send a verification email to your domain account email. Log into your Bluehost email client and click the verification email
  7. Back in Gmail, compose a new email and verify the newly added account is available in the From field

 

There you have it. We’ve successfully created a domain account email, forwarded emails to our personal account, and configured our personal account to respond as our domain account. This allows seamless receipt and response!

Linux Cronjob Doesn’t Execute Valid Python Script

Linux Cronjob Doesn’t Execute Valid Python Script

I’ve been using cron to execute a Python script used by my Raspberry Pi automatic cat feeder for some time now. After coming up with another script that needs to run on a regular schedule I added a second cronjob entry into the crontab.

That’s easy enough: first, in a terminal open the crontab to reveal existing jobs:

sudo nano crontab -e

Add the cronjob to the crontab by creating a new entry:

* * * * * /home/pi/Documents/Development/CatFeeder.py
* * * * * /home/pi/Documents/Development/Maintenance/Monitoring.py

The CatFeeder.py script has been running without a hitch, while the Monitoring.py script is the one being added.

After saving the file (this is nano, so CTRL+X, Y, Enter to save and exit) I expected the job to run every 60 seconds. However, nothing seemed to be happening. The new script never successfully executed. Meanwhile, the CatFeeder.py script was running flawlessly.

The script is an executable, I made sure of that by running chmod +x Monitoring.py, so that’s not the issue. I double-checked that the script ran without errors by invoking it manually: sudo python Monitoring.py. To no surprise the script ran as expected.

If the script runs fine, and a cronjob I already have in the crontab runs fine, then what gives?

SheBang #!: Specifying the Language Interpreter

There’s a very interesting line of code, or a comment rather, that I’ve noticed floating around in most of the Python scripts I’ve seen:

#!/usr/bin/env python

My tiny brain paid this line little attention at first, “how important could it be”, I thought. Enter the shebang #! character sequence. This sequence is treated as an interpreter directive by program loaders such as cron. That is, it specifies which interpreter to use when executing the script. 

Without this line of code the cronjob will not automatically use Python as the interpreter and will fail to execute the script. Add this line to the beginning of your script and watch your cronjob flourish!

What Was That You Said About the Script Running Without Issue?

It was previously mentioned that the Monitoring.py script executed without issue when invoked manually, like so:

sudo python Monitoring.py

This does indeed run without issue, even without the shebang #! line added to the file. However, the script name is preceded with the interpreter to use, python. If we execute the script a different way we’ll more accurately see what’s happening when the cronjob runs it.

In the terminal use the ./ command to execute the script:

./Monitoring.py

Without the shebang #!, Python is not used as the interpreter, and errors are shown in the terminal:

pi@raspberrypi:~/Documents/Development/Maintenance $ ./Monitoring.py
./Monitoring.py: line 2: import: command not found
./Monitoring.py: line 3: syntax error near unexpected token `1,'
./Monitoring.py: line 3: `sys.path.insert(1, os.path.join(sys.path[0], '..'))'

Now add the shebang #!/usr/bin/env python at the beginning of the script and execute it again. Unless your script has other syntactical problems it should run successfully.