tags:

views:

498

answers:

5

I am designing a system which will at some point require to send email notifications. So I am looking for a simple way to do this. Some background: the system will be running on Linux platform, there will be a working SMTP server somewhere on the network, the operator will configure its address, server credentials if required and a list of target email addresses (no, I am NOT working on a mass email system ;-). The process which will need to send the emails will be probably written in C, but super performance is not really a requirement, there won't be a lot of mails to send, so invoking some command-line tool is an acceptable option. Basically, what I tried in the past for similar tasks:

  • Invoking local sendmail in command-line mode. This is a nightmare, because of the necessity to support the cryptic sendmail config. This is what I would really like to avoid.
  • Talking to SMTP server port directly (EHLO, etc). This IS an option, but a bit too low-level for year 2008 ;-).
  • Using some MUA which talks to local sendmail daemon acting as a mail relay. This is not nice exactly because it requires having local sendmail up and configured.

So what I need is basically some library for C language or a simple command-line MUA which should be able to talk to remote sendmail (i.e. to talk to SMTP server that I tell it to), but not requiring a local mail relay.

Any ideas are welcome!

+4  A: 

mail(1) or mailx(1)
Also, since you have a local MTA you can pipe the message directly to sendmail(8) (which - despite its name - is a somewhat standard interface used by many MTA for injecting the mail)

Luca Tettamanti
I think both of those can only talk to a SMTP server on localhost, not on a remote one.
Paul Tomblin
True, but a standard Linux/Unix setup has a minimal MTA installed (not necessarily a full SMTP server) which is usually configured to relay all the mail to proper server.
Luca Tettamanti
This is exactly what I would like to avoid - using something that is "usually configured" in the right way. I don't understand why I need local sendmail if there is a properly configured sendmail daemon running elsewhere and accepting connections on port 25.
azerole
I see you point, but the local agent is there (otherwise other stuff start to break) it's just a matter of setting the correct relay; then your app can just send the mail and forget about it (no queuing, no retires, no fallback to secondary, etc.)
Luca Tettamanti
I recently worked on a project on Solaris platform, where one of security requirements was to stop all unneeded daemons. Sendmail was one of the daemons that we suppressed, and I am sure many Unix admins do the same on server platform. Expecting sendmail to run is only valid for desktop installs.
azerole
sendmail does not need to run as daemon in order to forward the email to a remote hub; postfix does need a few helpers but _not_ smtpd
Luca Tettamanti
luca is right. without at least a stub sendmail binary (like nullmailer, for example) you don't have a functional unix system.
hop
Luca is NOT right. I've used local sendmail in my past project as a local MTA and it was a nightmare, as no one else used sendmail on this machine the config file could contain anything; besides these configs are not compatible across sendmail versions, so every sendmail patch required config update
azerole
a) get a better distro / unix vendor. (btw. most linux distros won't even allow you to have no mta installed)
hop
b) now you have to follow patches in the 3rd-party lib and reconfigure your app instead of your mta when something regarding the gatway mx changes... how is that better?
hop
I fully aware that m4 is not exactly easy to grasp, but sendmail in null client mode is pretty simple to configure. Furthermore, as I said above, you can actually use any other nullmailer for this purpose, not necessarily sendmail.
Luca Tettamanti
+1  A: 

Here's a nice SMTP library, libESMTP

Vinko Vrsalovic
I will look closely into it, but it seems this one does the job! Thank you.
azerole
A: 

Perl's Mail::Mailer provides a very easy way to generate mail through the local MTA (example from perldoc -q mail):

use Mail::Mailer;

my $mailer = Mail::Mailer->new();
$mailer->open({
 From => $from_address,
 To      => $to_address,
 Subject => $subject,
}) or die "Can’t open: $!\n";
print $mailer $body;
$mailer->close();

If you're using C, you can either write a script wrapper around something using Mail::Mailer, or directly invoke the MTA via the shell and write formatted message into it.

Hudson
:-)I do NOT want to use local MTA, this is written in bold in my question.
azerole
A: 

Sorry, but what you're asking for isn't possible. In order to send mail to another system, you'll need some kind of program which transfers mail from one computer to another. Such a program is by definition an MTA.

You don't have to use Sendmail. You could, as other posters have tried to tell you, use something a lot more lightweight. All you need is something that can act as an SMTP client. You could even build the functionality into your program, but you'll still end up with what's essentially an MTA.

skoob
I am not asking a terminological question. I just don't want to impose on someone (including myself) the necessity to configure a system-wide mail relay, like sendmail. It's OK to built the MTA functionality inside the application. But not sendmail, please, please, have you seen the config??
azerole
Well, you can configure Exim or Postfix instead...
Vinko Vrsalovic
A: 

Have you tried sendEmail?

I have had success with a similar standalone Win32 commandline mail agent called Blat and am also looking for a similar solution on linux that does not require system support.

In the past I have used ssmtp as light weight alternative to sendmail although it typically requires system wide configuration and support. While this is useful for many application that require a functioning MTA, I understand that it does not solve your specific concern.

Marc