Friday, 27 March 2009

UPDATED: Using SSMTP to send mail via GMail

UPDATED July 2014, to reflect the fact that google smtp servers are on port 587 now.

Often you will have a bash script that requires the ability to send emails out, such as alerts and status updates. Or perhaps you just want to get the normal alerts that all Unix servers attempt to send from time to time.

Out of the box Linux systems don't send email unless they are configured to do so. You can muck about configuring sendmail to use a "smarthost" if you like or you can do what I do and use a simple little smtp service that is quick and easy to configure to send mails via a GMail account.

Note:
If you have your own domain then it is probably better to use sendmail to send mails direct rather than relaying mail via the Big G

Obviously, for this all to work you will need a GMail account of your own. Is GMail still invite only? I have no idea. If it is and you need an invite then enter a comment below with your email address and I will be happy to send you one!

OK, let's get started.

First we need to remove sendmail and install ssmtp

sudo apt-get remove sendmail
sudo apt-get install ssmtp mailutils


SSMTP requires a little configuring so edit /etc/ssmtp/ssmtp.conf;

sudo vi /etc/ssmtp/ssmtp.conf

Enter the details for the following fields;

mailhub = smtp.gmail.com:587
rewritedomain = tuxnetworks.com
AuthUser=myusername@gmail.com
AuthPass=mypassword
UseSTARTTLS=YES
UseTLS=YES


Note:
You should replace "tuxnetworks.com" with your own domain as well as provide the details for your GMail account. Using 'myusername' and 'mypassword' is a recipe for FAIL

Testing to see if things work.

Send an email from the command line like this;

mail -s "test config" myusername@gmail.com

To see if it was sent you can check /var/log/mail.log;

tail -f /var/log/mail.log

You should see your email logged as "SENT" in the output there.

Here is a sample ssmtp.conf for your convenience;
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster

AuthUser=myusername@gmail.com
AuthPass=mypassword
UseSTARTTLS=YES
UseTLS=YES

# place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com

# Where will the mail seem to come from?
rewriteDomain=tuxnetworks.com

# The full hostname
hostname=myserver.tuxnetworks.com

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=yes


And that's it! Simples!

[ Tested and confirmed on Lucid and Natty servers ]

Thursday, 12 March 2009

Disappearing network interfaces in Ubuntu Server

If you change network cards on ubuntu server then you will find that the new cards no longer come up. This also occurs when you copy a vmware virtual machine.

To fix this, edit the persistent-net-rules file

sudo vi /etc/udev/rules.d/70-persistent-net.rules

You should see a line (plus a commented heading) for the affected interface(s) like this;
# PCI device 0x14e4:0x1659 (r8169)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1c:c0:db:32:e7", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

(Forgive the formatting but blogger.com has a ridiculously narrow content column and long lines tend to disappear behind crap on the RHS of the page or wrap around and look like multiple lines)

Anyway, all you need to do is delete the line for the affected interface and reboot your system.

Once the system has rebooted, the persistent-net-rules file will be repopulated with the details for the new interface and your Ethernet adapter will be working once again.

Thursday, 5 March 2009

DEPRECIATED: Setting the hostname in gnome terminal

If you SSH to another host you might want to display the hostname of the remote host in the gnome terminal title bar

Put this code in your ~/.bashrc file;

case $TERM in
(xterm*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}($(id -ng))@${HOSTNAME}:
${PWD}\007"'
;;
esac

Sunday, 23 November 2008

Oblivion

So, I've been playing Oblivion a lot lately. What's that? A Windows game? Well, don't panic, I've been playing under Wine. It works perfectly with only the occasional crash. I've never played it under Windows so I don't know if this is usual or not but it wouldn't be the first windows game to have "issues".

Anyway, here a few tricks I've discovered.

1) Inventory woes

You don't need to play for long before you realise that you can't carry around anywhere near as much stuff as you want to and you are forced to discard stuff. This sucks.

Apparently, you can get around this by purchasing a house which is great but what about early in the game when you don't have the funds to do this? Well, what I've been doing is this;

Follow the main quest straight away until you get to the point where you have delivered the Amulet Of Kings to Jauffre. Go through the dialog and make sure you click on "Assistance". He will show you a chest full of stuff and invite you to take what you like. Well, I thought, I have some stuff that I am carrying around that I don't need right now so maybe I'll just pop that stuff in the chest. So far I've played for several hours with multiple saves and everything is still there, so I reckon that this will do as a storage facility until such a time that I can buy myself a house!

2) Invincible Meat Shield

Still on the main quest, you need to complete those up to the point where you are tasked with delivering Brother Martin to the Cloud Ruler Temple. Martin will start following you from that point. Cool, so now you can go dungeon exploring with Martin tagging along. He can't die and he will fight pretty well. You can keep this up for as long as you like I reckon as long as you don't go to the Cloud Ruler Temple.

Sunday, 19 October 2008

OOPS!


It seems someone at Telstra Bigpond is not managing their SSL cert's properly . . .

Thursday, 16 October 2008

Posting code to blogspot

I just found out how to post code snippets to blogspot

Use the (pre) & (code) tags to denote code segments (using normal html <> style tag brackets instead of the round ones used here)

(pre)(code)
Source code goes here
(/code)(/pre)


Once we replace the round tags we get output like this

Source code goes here

Tuesday, 16 September 2008

The End Of An Era

Sad news.

It seems the inmates have taken over the asylum over at my favourite tech news site, "The Register".

After nearly ten years of reading their site on a daily basis their horrendous new fixed width format is so utterly terrible that the site is no longer pleasant to read and I have to give up reading it.

They received a torrent of complaints to the comments section of their explanatory article entitled "OMFG what have you done?" and this is despite actively censoring many commenters. I myself was censored three times before I gave up and resorted to impotently whining about it on a blog that nobody reads. Other posters complained of the same censorship too, but maybe their moderators were so inundated with comments that many of them just fell into the bit-bucket at the end of the conveyer.

It doesn't matter anyway. It's their site, they can fcuk it up any way they please. It's hard to imagine why they would want to inflict such an appalling design on their readers but it seems they're quite willing to do so.

I have no idea what their motives are, other than change for change sake.

Idiots.