sSMTP gebruiken met Ubuntu

Voor het volledige artikel kijk je op bijgeplaatste sites:

http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/

sSmtp is an extremely simple, resource conserving, SMTP server that will allow your desktop or server to send email. In this article we are going to use sSMTP to send email through Gmail.

Sometimes we want to enable our servers/desktops to be able to send email without setting up a full featured mail server or configuring postfix to route through Gmail.

sSmtp is an extremely simple, resource conserving, SMTP server that will allow your desktop or server to send email. In this article we are going to use sSMTP to send outgoing email through Gmail.

Install sSMTP

Debian/Ubuntu users can Install with this command or click here to open up apt:

sudo apt-get install ssmtp

We need to then need to edit, ‘/etc/ssmtp/ssmtp.conf’:

root=username@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=username@gmail.com
UseSTARTTLS=YES
AuthUser=username
AuthPass=password
FromLineOverride=YES

Then add each account that you want to be able to send mail from by editing, ‘/etc/ssmtp/revaliases‘:

root:username@gmail.com:smtp.gmail.com:587
localusername:username@gmail.com:smtp.gmail.com:587

Now try sending an email

You can send an email through your favorite email client, like ‘mutt‘, or type:

sudo ssmtp someemail@email.com

You will then type your message, hit enter and ‘ctrl+d

Now that you have a simple outgoing email server setup, you can do all sorts of neat things:

  • Configure cron jobs to send log reports to your email address
  • Alert you of all kinds of system changes
  • Send email alerts when your computer reaches a certain temperature
  • Send email through PHP, Python, Ruby, and Perl

———

Just wanted to mention that if your using sSMTP from the CLI, that the format should look like this;

sudo ssmtp someemail@email.com

To: someemail@email.com
From: youremail@email.com
Subject: enter_subject_here

enter_body_here (then press enter when done to get a newline)
Then press ctrl-D

———-

Don’t use ’sudo’ unless you want your emails to appear from ‘root’.

Add ’smtp’ directory to the PATH of your normal USER, and run as normal user.

(Edit ‘/etc/ssmtp/revaliases’ with your normal user name as “localusername”, as in tutorial.)

========================================================

http://tombuntu.com/index.php/2008/10/21/sending-email-from-your-system-with-ssmtp/

Wouldn’t it be useful if your computer could email you? I’d like to be notified by email when my server is in trouble, but I don’t want to run my own mail server. sSMTP is perfect for this; it’s a simple way to send email from your system to an SMTP mail server, like Gmail’s.

Here’s how I set up sSMTP on Ubuntu to send mail through my Gmail account.

Install sSMTP from the package ssmtp (click the link to install), or by running the command below in your terminal:
sudo apt-get install ssmtp

sSMTP can be configured from one text file. Open /etc/ssmtp/ssmtp.conf in a text editor:
sudo gedit /etc/ssmtp/ssmtp.conf

The configuration file is very short and well commented by default. Here’s the options I use for sending mail through Gmail:
root=myemailaddress@gmail.com
mailhub=smtp.gmail.com:587
AuthUser=mygmailusername
AuthPass=mypassword
UseSTARTTLS=YES

If you’re using Gmail like I am, change the root, authuser, and authpass options to the email address, username, and password of your Google account. If you’re using another mail service you’ll need to change mailhub to the relevant SMTP server.

Once your configuration work is done, time to try sending some mail! The simplest way to do this is to run sSMTP in a terminal with a recipient email address:
ssmtp recipient_email@example.com

sSMTP will then wait for you to type your message, which needs to be formatted like this:
To: recipient_email@example.com
From: myemailaddress@gmail.com
Subject: test email

hello world!

Note the blank like after the subject, everything after this line is the body of the email. When you’re finished, press Ctrl-D. sSMTP may take a few seconds to send the message before closing.

Now it’s easy to write scripts which can send you mail. Here’s an example terminal command to send an email from the msg.txt text file:
ssmtp myemailaddress@gmail.com < msg.txt

msg.txt is a simple text using the proper formatting for sSMTP:
To: myemailaddress@gmail.com
From: myemailaddress@gmail.com
Subject: alert

The server is down!

=======================================================

Well, I don’t know about php, on http://www.w3schools.com/PHP/php_ref_mail.asp says it just needs a working mail system, so if you need to know only how to write the ssmtp.conf file, then I can help you with that. ssmtp will allow you to send mail directly from your computer through an external smtp server.
A working ssmtp.conf file:

root=postmaster #you probably won’t need to change it
mailhub=where.the.mail.goes.com #eg. stmp.someserver.com
hostname=what.goes.after.@.inyourmail #eg. domain.com
AuthUser=your.login.name #for the stmp account
AuthPass=your.password.for.it
AuthMethod=LOGIN # or CRAM-MD5

(ssmtp supports only these two authentication methods, check more at the manuals)

Geplaatst in Linux, Server beheer, Ubuntu
%d bloggers op de volgende wijze: