Simple way to send emails from C application on Unix

I am developing a system that will require email notifications at some point. So I am looking for an easy way to do this. Some background: the system will run on a Linux platform, there will be an SMTP server running somewhere on the network, the operator will set up their address, server credentials if required, and a list of target email addresses (no, I DON'T WORK a massive email system mail ;-). The process to be emailed will probably be written in C, but super performance is not really a requirement, there won't be a lot of emails to send, so calling some command line tool is an acceptable option. Basically what I've tried in the past for similar tasks:

  • Calling local sendmail in command line mode. This is a nightmare due to the need to maintain the cryptic sendmail configuration. This is what I really would like to avoid.
  • Talk directly to the port of the SMTP server (EHLO, etc.). This is an option, but too low for 2008; -).
  • Using some MUAs that negotiate with the local sendmail daemon to act as a mail relay. This is not very good because it requires local sendmail setup and configuration.

So what I need is basically a C library or a simple command line MUA that should be able to talk to a remote sendmail (i.e. talk to the SMTP server I'm talking about) , but not require a local mail relay .

Any ideas are appreciated!

+1


source to share


5 answers


Here's a good SMTP library, libESMTP



+1


source


mail (1) or mailx (1)
Also, since you have a local MTA, you can directly send a message to sendmail (8) (which, despite its name, is the standard interface used by many MTAs to enter mail)



+4


source


Perl Mail :: Mailer provides a very easy way to create mail via 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 are using C, you can write a wrapper script around anything with Mail :: Mailer, or call MTA directly through the wrapper and write a formatted message to it.

0


source


Sorry, but what you are asking is not possible. To send mail to another system, you need a program that transfers mail from one computer to another. Such a program is by definition an MTA.

You don't need to use Sendmail. You could, as the other posters have tried to tell you, use something much lighter. All you need is something that can act as an SMTP client. You could even create functionality in your program, but you still get what is essentially an MTA.

0


source


Have you tried sendEmail ?

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

In the past I have used ssmtp as a lightweight alternative to sendmail, although this usually requires general configuration and system support. While this is useful for many applications that require a valid MTA, I understand that it does not solve your specific problem.

0


source







All Articles