You are not logged in.

#1 2009-06-02 05:50:21

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

How to Send an Email in C Code Without using a Mail Server

I've got some C code I've been using to send an e-mail, but the code uses a system call to Postfix to do it. I'd like the code to be completely independent of Postfix; i.e., I don't want the end user to have to install and start the postfix daemon (or any other mail server) to use my code. Since I do not care about receiving e-mails (which would naturally require a daemon to be running all the time looking for the incoming data), but only sending an e-mail, is there a way in C code to simply send an e-mail, without dealing with a mail server? Ultimately, at some level, postfix is written in C so some part of it is able to autonomously send an e-mail... Does anyone know how that works?

Offline

#2 2009-06-02 05:56:10

Rotech
Member
Registered: 2009-06-02
Posts: 11

Re: How to Send an Email in C Code Without using a Mail Server

RFC for the SMTP protocol

http://www.ietf.org/rfc/rfc2821.txt

Offline

#3 2009-06-02 13:22:26

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: How to Send an Email in C Code Without using a Mail Server

Use a smtp lib.


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#4 2009-06-02 15:42:18

briest
Member
From: Katowice, PL
Registered: 2006-05-04
Posts: 468

Re: How to Send an Email in C Code Without using a Mail Server

Presence of /usr/sbin/sendmail (which does not need to be THE sendmail itself; all decent MTAs provide sendmail-compatible interface) is required by LSB, so you should not worry about it on most systems. On the other hand, some of them may be configured for local delivery only, or not at all...

Offline

#5 2009-06-02 16:37:09

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: How to Send an Email in C Code Without using a Mail Server

Hrm.. I know that when I first set up Arch Linux I did not have /usr/sbin/sendmail - I had to install Postfix (or a similar MTA) to get that binary. As such, and also because of what briest pointed out (that the system might not be configured for non-local delivery), I'd like to write my own sendmail() per se into my C code, rather than rely on /usr/sbin/sendmail.

I searched on google a bit for a free, open-source SMTP library and was able to find Emacs SMTP Library (http://www.gnu.org/software/emacs/manua … pmail.html) and vmime (http://www.vmime.org). But my question with these is, if I install the SMTP library and use it in my code, will not the end user also have to have an SMTP library installed to be able to compile my code?

Offline

#6 2009-06-02 19:28:38

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: How to Send an Email in C Code Without using a Mail Server

tony5429 wrote:

But my question with these is, if I install the SMTP library and use it in my code, will not the end user also have to have an SMTP library installed to be able to compile my code?

Not if you statically link it. You can do that with the -l (lowercase L) flag in gcc — for example, `gcc -l smtp foo.c -o foo`. However, the gcc(1) manpage doesn't [from my brief glance] make it clear whether that performs dynamic or static linking.

# Wait, sorry, I thought you were talking about using — not compiling — the code. Yes, they will probably need to have the library installed, but such is the case with many projects.

Last edited by Peasantoid (2009-06-02 19:30:43)

Offline

Board footer

Powered by FluxBB