3

Direct Question: I want to enable Perl to send emails. What package(s) should I install to setup a simplistic email server: no need for incoming, only outgoing. I can forward through gmail's SMTP if that's best?

Background: I am programmer with a nightly build script written in Perl. I would like to email myself the results of my nightly builds (especially if there's an error).

I've read about the perl package Mail::Sendmail briefly, but if something else is more appropriate, please tell me!!

I tried the simple aptget install sendmail, but that doesn't seem to work. I get the following errors:

Server said: 421 4.3.0 collect: Cannot write ./dfp1PFXl7W020719 (bfcommit, uid=0, gid=120): No such file or directory message transmission error (421 4.3.0 collect: Cannot write ./dfp1PFXl7W020719 (bfcommit, uid=0, gid=120): No such file or directory ) Server said: 421 4.3.0 collect: Cannot write ./dfp1PFXl7W020719 (bfcommit, uid=0, gid=120): No such file or directory

I've googled this problem a bit and tried a few things -- adding my username to /etc/mail/trusted-users and such, but to no avail.

In other words, I would be most grateful if you could provide simple instructions for setting up an outgoing mail server. I really don't understand the specifics, but as I understand, I need to forward the mail through an existing SMTP server -- so I can use my gmail account if need be (that's where I want to send the logs anyway). Any suggestions would be most greatly appreciated.

5 Answers 5

3

All of them are too much tool for the job. ssmtp does this - but only this.

sudo apt-get install ssmtp

(This will remove postfix or sendmail if installed.)

sudoedit /etc/ssmtp/ssmtp.conf

And the contents of that file:

[email protected]
Mailhub=smtp.gmail.com:465
RewriteDomain=gmail.com
AuthUser=your_gmail_username # (before the @gmail.com part)
AuthPass=your_gmail_password
FromLineOverride=Yes
UseTLS=Yes
3

I still maintain that dovecot-postfix is easy to install and configure.
I have some more detail in my answer to Is There a Simple Mail-Server I Can Install?

There, EmmyS was able to get this to work for her phpmail function.

Dovecot-postfix does more heavy-lifting than perhaps you need, but it takes just a couple of configuration items after:

sudo apt-get install dovecot-postfix
2

You could also look at Net::SMTP which allows you to send SMTP messages without requiring any external programs such as sendmail. This might be a little off-topic for Ask Ubuntu as this is a pure Perl solution, but you might find it preferable. Net::SMTP is provided by the perl-modules package, which should be installed by default.

1
  • Yes, while a little off topic, this is the solution I went with to avoid installing unnecessary services on my server. FWIW, using TLS (for gmail auth) with Net::SMTP took me a bit, but it's package Net::SMTP::TLS, has essentially the same interface.
    – M. Tibbits
    Feb 26, 2011 at 21:09
2

It seems there are many mail servers running, could you try to shutdown sendmail?

sudo /etc/init.d/sendmail stop

and check your smtp port (25) with

sudo lsof -i -P -R | grep ':25 '

if you see the port 25 there is another process running, try to stop it. The pid is in the third column of the output.

To properly configure postfix: set to low level debconf

sudo dpkg-reconfigure debconf

choose dialog and then low level of warning. Then install postfix with

sudo apt-get install postfix 

choose the standard option with "Internet site" profile. If you have installed postfix previously you can reconfigure it by:

sudo dpkg-reconfigure postfix

Enjoy!

2

For the perl side Perl::SendMail will work if you have a local relay like SSMTP, or any other similar program. It does not appear to do authentication.

I found a post on Sending email via GMAIL using Perl. Please be aware that the code will have your Google credentials. (As will SSMTP or whatever other relay you use.)

I would suggest you use your ISPs relay server to send the mail. You could use Perl::Sendmail standalone in that case.

Recommended solution: Postfix gets installed as a dependency by many programs requiring a mail server. If it isn't already installed, install it or Exim4. Configure your server for "mail sent by smarthost; not local mail" using your ISP's relay as the smarthost. Configure /etc/email-addresses for you userid. Also configure /etc/aliases to forward email to your gmail account.

If you use cron to run you build any output to either stdout or stderr will be emailed to you. You can also use mailx to send mail if you want to send mail from a script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .