looking for small SMTP lib? - Unix

This is a discussion on looking for small SMTP lib? - Unix ; I need to write a small shared object that will send a mail message under certain circumstances. I was going to use SMTP to do this (just open a socket and send the message parsing what the server sends etc...). ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: looking for small SMTP lib?

  1. looking for small SMTP lib?

    I need to write a small shared object that will send a mail message
    under certain circumstances. I was going to use SMTP to do this (just
    open a socket and send the message parsing what the server sends
    etc...). But I would presume someone has done this before, but I could
    not find anything (except full fledged SMTP libraries). I can not exec
    sendmail or other processes.

    Thanks

  2. Re: looking for small SMTP lib?

    Jim Marshall writes:
    > I need to write a small shared object that will send a mail message
    > under certain circumstances. I was going to use SMTP to do this (just
    > open a socket and send the message parsing what the server sends
    > etc...). But I would presume someone has done this before, but I could
    > not find anything (except full fledged SMTP libraries). I can not exec
    > sendmail or other processes.


    Below is a part of a 'mail sending script' used for some time
    on the appliances I mostly work for:

    cd $temp
    printf "HELO lamer\r\n" >header
    printf "MAIL FROM: %s\r\n" "$addr" >>header
    printf "RCPT TO: %s\r\n" "$addr" >>header
    printf "DATA\r\n" >>header

    printf ".\r\nQUIT\r\n" >trailer

    cat header - trailer | nc "$server" 25

    It should be easy to adapt this for C.

  3. Re: looking for small SMTP lib?

    Hi Jim!

    Jim Marshall wrote:
    > I need to write a small shared object that will send a mail message
    > under certain circumstances. I was going to use SMTP to do this (just
    > open a socket and send the message parsing what the server sends
    > etc...). But I would presume someone has done this before, but I could
    > not find anything (except full fledged SMTP libraries). I can not exec
    > sendmail or other processes.

    Perhaps you should have a look at libesmtp?
    [ http://www.stafford.uklinux.net/libesmtp/ ]

    HTH. Salut, Jörg

    --
    gpg/pgp key # 0xd7fa4512
    fingerprint 4e89 6967 9cb2 f548 a806 7e8b fcf4 2053 d7fa 4512

  4. Re: looking for small SMTP lib?

    Jörg Schmitz-Linneweber wrote:
    > Hi Jim!
    >
    > Jim Marshall wrote:
    >> I need to write a small shared object that will send a mail message
    >> under certain circumstances. I was going to use SMTP to do this (just
    >> open a socket and send the message parsing what the server sends
    >> etc...). But I would presume someone has done this before, but I could
    >> not find anything (except full fledged SMTP libraries). I can not exec
    >> sendmail or other processes.

    > Perhaps you should have a look at libesmtp?
    > [ http://www.stafford.uklinux.net/libesmtp/ ]
    >
    > HTH. Salut, Jörg
    >

    thanks!

  5. looking for small SMTP lib?

    RW> Below is a part of a 'mail sending script' used for
    RW> some time on the appliances I mostly work for:
    RW>
    RW> cd $temp
    RW> printf "HELO lamer\r\n" >header
    RW> printf "MAIL FROM: %s\r\n" "$addr" >>header
    RW> printf "RCPT TO: %s\r\n" "$addr" >>header
    RW> printf "DATA\r\n" >>header
    RW>
    RW> printf ".\r\nQUIT\r\n" >trailer
    RW>
    RW> cat header - trailer | nc "$server" 25
    RW>
    RW> It should be easy to adapt this for C.

    .... and when you do, remember to fix the several bugs that it has.
    Angle brackets are mandatory in the MAIL and RCPT verbs, and so is dot-
    stuffing for the message data. Sending message data and the end of
    data indication is prohibited unless there is a positive
    acknowledgement to the DATA verb. (The consequences of sending
    arbitrary data when the sever is not actually in the receiving message
    data state should be obvious.) Don't contribute to furthering
    Gresham's Law when it comes to SMTP. If you are going to write an
    SMTP Submission client, write a correct one.


  6. Re: looking for small SMTP lib?

    In article <1193409669.201203.211210@50g2000hsm.googlegroups.c om>,
    J de Boyne Pollard wrote:

    > If you are going to write an
    > SMTP Submission client, write a correct one.


    Which explains why the OP is looking for a library, and why this is a
    Good Thing. He presumably knows that he doesn't know the SMTP protocol
    well, so anything he cobbled together would probably not be fully
    correct. One hopes that a library that people recommend would implement
    the protocol well.

    I'm not sure there are many such libraries, though. Most Unix
    applications that need to send mail simply exec a program like mail,
    mailx, or sendmail.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  7. Re: looking for small SMTP lib?

    Barry Margolin wrote:

    > I'm not sure there are many such libraries, though. Most Unix
    > applications that need to send mail simply exec a program like mail,
    > mailx, or sendmail.


    There are SMTP client libraries. If you're willing to use Perl,
    Net::SMTP is not bad. A free C library is
    http://www.stafford.uklinux.net/libesmtp/

    -- David.


  8. looking for small SMTP lib?

    BM> I'm not sure there are many such libraries, though.
    BM> Most Unix applications that need to send mail
    BM> simply exec a program like mail, mailx, or sendmail.

    That was specifically ruled out as a solution. But I did wonder at
    the thinking behind that restriction. I suspect that it is
    misguided. I suspect that there is no inherent reason that the
    application cannot fork() and execve() a mail submission utility
    program; and that the thinking is that it is intended, probably for
    security reasons, that the host system should not have a full MTS
    installed. In which case, it would be incorrect to entirely rule out
    using a submission utility program. There are plenty of ways in which
    a system can be set up with a small, secure, MTS, without an SMTP
    server, a queue, local delivery, or other such accoutrements, whose
    submission utility simply passes all submitted mail straight over to
    another system for handling. One could quite easily use "mini-
    qmail" (), for example, and have
    the normal fork-and-exec-the-submission-utility approach in one's
    application.


  9. looking for small SMTP lib?

    RW> Below is a part of a 'mail sending script' used for
    RW> some time on the appliances I mostly work for:
    RW>
    RW> cd $temp
    RW> printf "HELO lamer\r\n" >header
    RW> printf "MAIL FROM: %s\r\n" "$addr" >>header
    RW> printf "RCPT TO: %s\r\n" "$addr" >>header
    RW> printf "DATA\r\n" >>header
    RW>
    RW> printf ".\r\nQUIT\r\n" >trailer
    RW>
    RW> cat header - trailer | nc "$server" 25
    RW>
    RW> It should be easy to adapt this for C.

    JdeBP> ... and when you do, remember to fix the several bugs that it
    JdeBP> has. [...]

    RW> The point of this script was to send a mail to a
    RW> particular mail server. Which it did.

    It does not operate correctly. I pointed out the several problems,
    one of which would corrupt messages and two of which are egregious
    security holes that can potentially be exploited to create an open
    relay, in the portion of the message that you skipped over above.
    (There's a third security hole that I didn't point out, but that
    people familiar with PHP scripts that send mail from web forms should
    be familiar with.) The script simply does not implement the protocol
    at all.

    RW> This is called 'a quick hack', a concept you
    RW> don't seem to be familar with.

    I see that once again you have resorted to accusing the poster when
    you lack any technical foundation for discussing the subject at hand.
    A correct description for what you have above is not "quick hack", but
    "yet another half-baked and incorrect SMTP client that contributes to
    furthering Gresham's Law". It is an SMTP client that is broken and
    should not be used, especially not as a model for other people to
    develop SMTP clients of their own from.


+ Reply to Thread